Custom Train Tracks: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (→‎Issues: add issues)
m (fix typo)
 
(7 intermediate revisions by the same user not shown)
Line 7: Line 7:
|-
|-
|'''Branch'''
|'''Branch'''
|[https://github.com/multitheftauto/mtasa-blue/tree/custom-train-tracks custom-train-tracks]
|[https://github.com/multitheftauto/mtasa-blue/tree/feature/custom-train-tracks feature/custom-train-tracks]
|-
|-
|'''Branch version'''
|'''Branch version'''
|1.6
|1.5.3
|}
|}


Line 30: Line 30:


track = TrainTrack(...nodes) -- createTrack(node1, node2, node3, ...)
track = TrainTrack(...nodes) -- createTrack(node1, node2, node3, ...)
 
track:getNodes() returns a table of Vector3s
track:getLength() -- getTrainTrack(track)
-- Default track functions
-- Default track functions
TrainTrack.removeDefault(int trackID)
TrainTrack.removeDefault(int trackID)
Line 36: Line 37:


-- These functions already exist, but I'm not sure how these lengths are used or what they are for
-- These functions already exist, but I'm not sure how these lengths are used or what they are for
float track:getLength() -- getTrainTrack(track)
 
bool track:setLength(float length) -- setTrackLength(track, float length)
</syntaxhighlight>
</syntaxhighlight>


Line 43: Line 43:
All information related custom train tracks are stored here.
All information related custom train tracks are stored here.


<section name="Files" show="true">
==== Files ====
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
MTA10/game_sa
MTA10/game_sa
Line 62: Line 62:
** luadefs/CLuaTrainTrackDefs.{cpp,h} -- contain definitions for the Lua API
** luadefs/CLuaTrainTrackDefs.{cpp,h} -- contain definitions for the Lua API
</syntaxhighlight>
</syntaxhighlight>
</section>
 
==== m_OriginalTrainTrackData ====
The [https://pastebin.mtasa.com/748483851 m_OriginalTrainTrackData array] contains the same values in CTrainTrackManager.cpp and CTrainTrackManagerSA.cpp.
 
The Init function is structured like so (pay special attention to the comments):
<syntaxhighlight lang="lua">
typedef struct
{
    short sX;              // x coordinate times 8
    short sY;              // y coordinate times 8
    short sZ;              // z coordinate times 8
    float fRailDistance;    // on-rail distance ( leave the client to calculate this )
    void Init ( short sX, short sY, short sZ, unsigned short sRailDistance, WORD padding )
    {
        this->sX = sX;
        this->sY = sY;
        this->sZ = sZ;
        this->fRailDistance = sRailDistance;
    }
} SRailNode;
</syntaxhighlight>
 
We need to make sense of the following things:
 
* Why is padding an argument here? (It doesn't do anything, and when Init() is called, real values are provided)
* Why are values repeated several times?
* Why does the last repeat have slightly different values?


=== Issues ===
=== Issues ===
Line 73: Line 99:


=== Re-merge ===
=== Re-merge ===
<section name="This section has been archived" collapse="true">
{| class="wikitable" style="width: auto; table-layout: fixed;"
{| class="wikitable" style="width: auto; table-layout: fixed;"
|-
|-
Line 103: Line 130:
* ... Merged revision(s) 6092-6137 from trunk [https://github.com/multitheftauto/mtasa-blue/commit/61976a30a1edda6150d1840833ab8ac2d22ae59a 61976a30a1edda6150d1840833ab8ac2d22ae59a]
* ... Merged revision(s) 6092-6137 from trunk [https://github.com/multitheftauto/mtasa-blue/commit/61976a30a1edda6150d1840833ab8ac2d22ae59a 61976a30a1edda6150d1840833ab8ac2d22ae59a]


This means that there are only four commits that need to be merged into the new branch. There is currently a packet issue introduced by the merge that needs to be fixed.
This means that there are only four commits that need to be merged into the new branch. <strike>There is currently a packet issue introduced by the merge that needs to be fixed.</strike>
 
</section>
[[Category: Development]]
[[Category: Development]]

Latest revision as of 22:12, 3 October 2016

This branch makes it possible to make your own train tracks.

Status Work in progress
Branch feature/custom-train-tracks
Branch version 1.5.3

Functions

Media

Development

API

-- trainNode is a Vector3, or table of three coordinates
-- nodes is a table of trainNodes

track = TrainTrack(...nodes) -- createTrack(node1, node2, node3, ...)
track:getNodes() returns a table of Vector3s
track:getLength() -- getTrainTrack(track)
-- Default track functions
TrainTrack.removeDefault(int trackID)
TrainTrack.resetDefault(int trackID)

-- These functions already exist, but I'm not sure how these lengths are used or what they are for

Findings

All information related custom train tracks are stored here.

Files

MTA10/game_sa
** CTrainTrackManagerSA.{cpp,h}
** CTrainTrackSA.{cpp,h}

MTA10/mods/shared_logic
** CClientTrainTrack.{cpp,h}
** luadefs/CLuaTrainTrackDefs.{cpp,h} -- contain definitions for the Lua API

MTA10/sdk/game
** CTrainTrack.h
** CTrainTrackManager.h

MTA10_Server/mods/deathmatch/logic
** CTrainTrackManager.{cpp,h}
** CTrainTrack.{cpp,h}
** luadefs/CLuaTrainTrackDefs.{cpp,h} -- contain definitions for the Lua API

m_OriginalTrainTrackData

The m_OriginalTrainTrackData array contains the same values in CTrainTrackManager.cpp and CTrainTrackManagerSA.cpp.

The Init function is structured like so (pay special attention to the comments):

typedef struct
{
    short sX;               // x coordinate times 8
    short sY;               // y coordinate times 8
    short sZ;               // z coordinate times 8
    float fRailDistance;    // on-rail distance ( leave the client to calculate this )
    void Init ( short sX, short sY, short sZ, unsigned short sRailDistance, WORD padding )
    {
        this->sX = sX;
        this->sY = sY;
        this->sZ = sZ;
        this->fRailDistance = sRailDistance;
    }
} SRailNode;

We need to make sense of the following things:

  • Why is padding an argument here? (It doesn't do anything, and when Init() is called, real values are provided)
  • Why are values repeated several times?
  • Why does the last repeat have slightly different values?

Issues

  • There may be some issues (relating to infinite loops) if a track runs across another or crosses another
    • Infinite loop occurs at 006f8fda, see call stack. Occurs when a track of two nodes have same x/y, but different z. Only occurs for tracks that ONLY consist of nodes atop each other.
      • Possible solution: when creation tracks, ensure that atleast one of the nodes has a different x/y to any other node.
  • Tracks may not be cleaned up -> See CTrainTrackManager::ResetTracks
  • See CTrainTrackManager and CTrainTrackManagerSA - why is this file so big? Why are coordinates provided multiple times for the same track? Which ones are right?
  • int CWorldSA::FindClosestRailTrackNode needs updating. It needs to use MAX_TOTAL_TRACKS and the train manager. See 09e3ee8f25810c17742

Re-merge

Click to expand [+]
This section has been archived