Changeset 18710

Timestamp:
Sep 6, 2016, 11:49:57 PM (8 years ago)
Author:
FeXoR
Message:

Adds globalscripts/BicubicInterpolation.js, the corresponding license_mit.txt and points to it for other files with the same license in LICENSE.txt - reviewed by Philip and Itms. Uses that to fix an interpolation issue in gaia.js and also fixes a "fail by one" there - reviewed by elexis. Fixes #4174

Location:
ps/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/LICENSE.txt

    r16705 r18710  
    3838
    3939  /build/premake/*.lua
    40     MIT
     40    MIT
    4141
    4242  /docs
     
    5050
    5151  /source/lib
    52     MIT
     52    MIT
    5353
    5454  /source/scriptinterface/third_party
     
    6161    GPL version 2 (or later)
    6262    ISC (pkcs5_pbkdf2.cpp)
    63     MIT (pkcs5_pbkdf2.h)
     63    MIT (pkcs5_pbkdf2.h)
    6464
    6565  /source/third-party/jsonspirit
    66     MIT
     66    MIT
    6767
    6868  /source/third_party/mikktspace
     
    7070
    7171  /source/third_party/mongoose
    72     MIT
     72    MIT
    7373
    7474  /source/third_party/tinygettext
     
    8080  /source/tools/atlas
    8181    GPL version 2 (or later) - see license_gpl-2.0.txt
     82
     83
     84
  • ps/trunk/binaries/data/mods/public/maps/random/rmgen2/gaia.js

    r18650 r18710  
    12751275 * @param tilemap - The IDs of the palletmap to be painted for each heightmap tile
    12761276 * @param pallet - The tile texture names used by the tilemap.
    1277  * @returns the ratio of heightmap tiles per map size tiles
     1277 * @return the ratio of heightmap tiles per map size tiles
    12781278 */
    12791279function paintHeightmap(heightmap, tilemap, pallet, func = undefined)
    12801280{
    1281     let lastI = -1;
    1282     let mapSize = getMapSize();
     1281    let mapSize = getMapSize(); // Width of the map in terrain tiles
    12831282    let hmSize = Math.sqrt(heightmap.length);
    1284     let scale = hmSize / mapSize;
    1285 
    1286     for (let y = 0; y < mapSize; ++y)
    1287         for (let x = 0; x < mapSize; ++x)
    1288         {
    1289             let i = Math.floor(x * scale) * hmSize + Math.floor(y * scale);
    1290 
    1291             let height = heightmap[i];
    1292             let tile = pallet[tilemap[i]];
    1293 
    1294             if (i == lastI)
     1283    let scale = hmSize / (mapSize + 1); // There are mapSize + 1 vertices (each 1 tile is surrounded by 2x2 vertices)
     1284
     1285    for (let x = 0; x <= mapSize; ++x)
     1286        for (let y = 0; y <= mapSize; ++y)
     1287        {
     1288            let hmPoint = { "x": x * scale, "y": y * scale };
     1289            let hmTile = { "x": Math.floor(hmPoint.x), "y": Math.floor(hmPoint.y) };
     1290            let shift = { "x": 0, "y": 0 };
     1291
     1292            if (hmTile.x == 0)
     1293                shift.x = 1;
     1294            else if (hmTile.x == hmSize - 1)
     1295                shift.x = - 2;
     1296            else if (hmTile.x == hmSize - 2)
     1297                shift.x = - 1;
     1298
     1299            if (hmTile.y == 0)
     1300                shift.y = 1;
     1301            else if (hmTile.y == hmSize - 1)
     1302                shift.y = - 2;
     1303            else if (hmTile.y == hmSize - 2)
     1304                shift.y = - 1;
     1305
     1306            let neighbors = [];
     1307            for (let localYi = 0; localYi < 4; ++localYi)
     1308                for (let localXi = 0; localXi < 4; ++localXi)
     1309                    neighbors.push(heightmap[(hmTile.x + localXi + shift.x - 1) * hmSize + (hmTile.y + localYi + shift.y - 1)]);
     1310
     1311            setHeight(x, y, bicubicInterpolation(hmPoint.x - hmTile.x - shift.x, hmPoint.y - hmTile.y - shift.y, ...neighbors) / scale);
     1312
     1313            if (x < mapSize && y < mapSize)
    12951314            {
    1296                 let nearby = [i];
    1297 
    1298                 if (i + hmSize < heightmap.length)
    1299                 {
    1300                     nearby.push(i + hmSize);
    1301                     height = (heightmap[nearby[0]] + heightmap[nearby[1]]) / 2;
    1302                 }
    1303 
    1304                 tile = pallet[tilemap[nearby[randInt(0, nearby.length - 1)]]];
     1315                let i = hmTile.x * hmSize + hmTile.y;
     1316                let tile = pallet[tilemap[i]];
     1317                placeTerrain(x, y, tile);
     1318
     1319                if (func)
     1320                    func(tile, x, y);
    13051321            }
    1306 
    1307             setHeight(x, y, height / scale);
    1308             placeTerrain(x, y, tile);
    1309 
    1310             if (func)
    1311                 func(tile, x, y);
    1312 
    1313             lastI = i;
    13141322        }
    13151323
Note: See TracChangeset for help on using the changeset viewer.