3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 //#include "serverobject.h"
28 #include "content_sao.h"
30 #include "content_mapnode.h" // For content_mapnode_get_new_name
31 #include "voxelalgorithms.h"
33 #include "settings.h" // For g_settings
34 #include "main.h" // For g_profiler
36 #include "mapgen_v6.h"
37 #include "mapgen_v7.h"
39 FlagDesc flagdesc_mapgen[] = {
42 {"dungeons", MG_DUNGEONS},
43 {"v6_jungles", MGV6_JUNGLES},
44 {"v6_biome_blend", MGV6_BIOME_BLEND},
49 FlagDesc flagdesc_ore[] = {
50 {"absheight", OREFLAG_ABSHEIGHT},
51 {"scatter_noisedensity", OREFLAG_DENSITY},
52 {"claylike_nodeisnt", OREFLAG_NODEISNT},
57 ///////////////////////////////////////////////////////////////////////////////
60 Ore *createOre(OreType type) {
63 return new OreScatter;
66 //case ORE_CLAYLIKE: //TODO: implement this!
67 // return new OreClaylike;
80 void Ore::resolveNodeNames(INodeDefManager *ndef) {
81 if (ore == CONTENT_IGNORE) {
82 ore = ndef->getId(ore_name);
83 if (ore == CONTENT_IGNORE) {
84 errorstream << "Ore::resolveNodeNames: ore node '"
85 << ore_name << "' not defined";
87 wherein = CONTENT_AIR;
91 if (wherein == CONTENT_IGNORE) {
92 wherein = ndef->getId(wherein_name);
93 if (wherein == CONTENT_IGNORE) {
94 errorstream << "Ore::resolveNodeNames: wherein node '"
95 << wherein_name << "' not defined";
97 wherein = CONTENT_AIR;
103 void Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
106 in_range |= (nmin.Y <= height_max && nmax.Y >= height_min);
107 if (flags & OREFLAG_ABSHEIGHT)
108 in_range |= (nmin.Y >= -height_max && nmax.Y <= -height_min) << 1;
113 if (in_range & ORE_RANGE_MIRROR) {
114 ymin = MYMAX(nmin.Y, -height_max);
115 ymax = MYMIN(nmax.Y, -height_min);
117 ymin = MYMAX(nmin.Y, height_min);
118 ymax = MYMIN(nmax.Y, height_max);
120 if (clust_size >= ymax - ymin + 1)
125 generate(mg->vm, mg->seed, blockseed, nmin, nmax);
129 void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
130 u32 blockseed, v3s16 nmin, v3s16 nmax) {
131 PseudoRandom pr(blockseed);
132 MapNode n_ore(ore, 0, ore_param2);
134 int volume = (nmax.X - nmin.X + 1) *
135 (nmax.Y - nmin.Y + 1) *
136 (nmax.Z - nmin.Z + 1);
137 int csize = clust_size;
138 int orechance = (csize * csize * csize) / clust_num_ores;
139 int nclusters = volume / clust_scarcity;
141 for (int i = 0; i != nclusters; i++) {
142 int x0 = pr.range(nmin.X, nmax.X - csize + 1);
143 int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
144 int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
146 if (np && (NoisePerlin3D(np, x0, y0, z0, seed) < nthresh))
149 for (int z1 = 0; z1 != csize; z1++)
150 for (int y1 = 0; y1 != csize; y1++)
151 for (int x1 = 0; x1 != csize; x1++) {
152 if (pr.range(1, orechance) != 1)
155 u32 i = vm->m_area.index(x0 + x1, y0 + y1, z0 + z1);
156 if (vm->m_data[i].getContent() == wherein)
157 vm->m_data[i] = n_ore;
163 void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
164 u32 blockseed, v3s16 nmin, v3s16 nmax) {
165 PseudoRandom pr(blockseed + 4234);
166 MapNode n_ore(ore, 0, ore_param2);
168 int max_height = clust_size;
169 int y_start = pr.range(nmin.Y, nmax.Y - max_height);
172 int sx = nmax.X - nmin.X + 1;
173 int sz = nmax.Z - nmin.Z + 1;
174 noise = new Noise(np, 0, sx, sz);
176 noise->seed = seed + y_start;
177 noise->perlinMap2D(nmin.X, nmin.Z);
180 for (int z = nmin.Z; z <= nmax.Z; z++)
181 for (int x = nmin.X; x <= nmax.X; x++) {
182 float noiseval = noise->result[index++];
183 if (noiseval < nthresh)
186 int height = max_height * (1. / pr.range(1, 3));
187 int y0 = y_start + np->scale * noiseval; //pr.range(1, 3) - 1;
188 int y1 = y0 + height;
189 for (int y = y0; y != y1; y++) {
190 u32 i = vm->m_area.index(x, y, z);
191 if (!vm->m_area.contains(i))
194 if (vm->m_data[i].getContent() == wherein)
195 vm->m_data[i] = n_ore;
201 Decoration *createDecoration(DecorationType type) {
204 return new DecoSimple;
205 //case DECO_SCHEMATIC:
206 // return new DecoSchematic;
208 // return new DecoLSystem;
215 Decoration::~Decoration() {
220 void Decoration::resolveNodeNames(INodeDefManager *ndef) {
221 if (c_place_on == CONTENT_IGNORE)
222 c_place_on = ndef->getId(place_on_name);
226 void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
227 PseudoRandom ps(blockseed + 53);
228 int carea_size = nmax.X - nmin.X + 1;
230 // Divide area into parts
231 if (carea_size % sidelen) {
232 errorstream << "Decoration::placeDeco: chunk size is not divisible by "
233 "sidelen; setting sidelen to " << carea_size << std::endl;
234 sidelen = carea_size;
237 s16 divlen = carea_size / sidelen;
238 int area = sidelen * sidelen;
240 for (s16 z0 = 0; z0 < divlen; z0++)
241 for (s16 x0 = 0; x0 < divlen; x0++) {
242 v2s16 p2d_center( // Center position of part of division
243 nmin.X + sidelen / 2 + sidelen * x0,
244 nmin.Z + sidelen / 2 + sidelen * z0
246 v2s16 p2d_min( // Minimum edge of part of division
247 nmin.X + sidelen * x0,
248 nmin.Z + sidelen * z0
250 v2s16 p2d_max( // Maximum edge of part of division
251 nmin.X + sidelen + sidelen * x0 - 1,
252 nmin.Z + sidelen + sidelen * z0 - 1
255 // Amount of decorations
257 NoisePerlin2D(np, p2d_center.X, p2d_center.Y, mapseed) :
259 u32 deco_count = area * MYMAX(nval, 0.f);
261 for (u32 i = 0; i < deco_count; i++) {
262 s16 x = ps.range(p2d_min.X, p2d_max.X);
263 s16 z = ps.range(p2d_min.Y, p2d_max.Y);
265 int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X);
267 s16 y = mg->heightmap ?
268 mg->heightmap[mapindex] :
269 mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
271 if (y < nmin.Y || y > nmax.Y)
274 int height = getHeight();
275 int max_y = nmax.Y + MAP_BLOCKSIZE;
276 if (y + 1 + height > max_y) {
279 printf("Decoration at (%d %d %d) cut off\n", x, y, z);
281 JMutexAutoLock cutofflock(cutoff_mutex);
282 cutoffs.push_back(CutoffData(x, y, z, height));
287 std::set<u8>::iterator iter;
290 iter = biomes.find(mg->biomemap[mapindex]);
291 if (iter == biomes.end())
296 generate(mg, &ps, max_y, 0, v3s16(x, y, z));
303 void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
304 PseudoRandom pr(blockseed + 53);
305 std::vector<CutoffData> handled_cutoffs;
307 // Copy over the cutoffs we're interested in so we don't needlessly hold a lock
309 JMutexAutoLock cutofflock(cutoff_mutex);
310 for (std::list<CutoffData>::iterator i = cutoffs.begin();
311 i != cutoffs.end(); ++i) {
312 CutoffData cutoff = *i;
314 s16 height = cutoff.height;
315 if (p.X < nmin.X || p.X > nmax.X ||
316 p.Z < nmin.Z || p.Z > nmax.Z)
318 if (p.Y + height < nmin.Y || p.Y > nmax.Y)
321 handled_cutoffs.push_back(cutoff);
325 // Generate the cutoffs
326 for (size_t i = 0; i != handled_cutoffs.size(); i++) {
327 v3s16 p = handled_cutoffs[i].p;
328 s16 height = handled_cutoffs[i].height;
330 if (p.Y + height > nmax.Y) {
331 //printf("Decoration at (%d %d %d) cut off again!\n", p.X, p.Y, p.Z);
332 cuttoffs.push_back(v3s16(p.X, p.Y, p.Z));
335 generate(mg, &pr, nmax.Y, nmin.Y - p.Y, v3s16(p.X, nmin.Y, p.Z));
338 // Remove cutoffs that were handled from the cutoff list
340 JMutexAutoLock cutofflock(cutoff_mutex);
341 for (std::list<CutoffData>::iterator i = cutoffs.begin();
342 i != cutoffs.end(); ++i) {
344 for (size_t j = 0; j != handled_cutoffs.size(); j++) {
345 CutoffData coff = *i;
346 if (coff.p == handled_cutoffs[j].p)
347 i = cutoffs.erase(i);
355 void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
356 Decoration::resolveNodeNames(ndef);
358 if (c_deco == CONTENT_IGNORE) {
359 c_deco = ndef->getId(deco_name);
360 if (c_deco == CONTENT_IGNORE) {
361 errorstream << "DecoSimple::resolveNodeNames: decoration node '"
362 << deco_name << "' not defined";
363 c_deco = CONTENT_AIR;
366 if (c_spawnby == CONTENT_IGNORE) {
367 c_spawnby = ndef->getId(spawnby_name);
368 if (c_spawnby == CONTENT_IGNORE) {
369 errorstream << "DecoSimple::resolveNodeNames: spawnby node '"
370 << deco_name << "' not defined";
372 c_spawnby = CONTENT_AIR;
376 if (c_decolist.size())
379 for (size_t i = 0; i != decolist_names.size(); i++) {
380 content_t c = ndef->getId(decolist_names[i]);
381 if (c == CONTENT_IGNORE) {
382 errorstream << "DecoSimple::resolveNodeNames: decolist node '"
383 << decolist_names[i] << "' not defined";
386 c_decolist.push_back(c);
391 void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, s16 start_y, v3s16 p) {
392 ManualMapVoxelManipulator *vm = mg->vm;
394 u32 vi = vm->m_area.index(p);
395 if (vm->m_data[vi].getContent() != c_place_on &&
396 c_place_on != CONTENT_IGNORE)
399 if (nspawnby != -1) {
401 v3s16 dirs[8] = { // a Moore neighborhood
412 for (int i = 0; i != 8; i++) {
413 u32 index = vm->m_area.index(p + dirs[i]);
414 if (vm->m_area.contains(index) &&
415 vm->m_data[index].getContent() == c_spawnby)
419 if (nneighs < nspawnby)
423 size_t ndecos = c_decolist.size();
424 content_t c_place = ndecos ? c_decolist[pr->range(0, ndecos - 1)] : c_deco;
426 s16 height = (deco_height_max > 0) ?
427 pr->range(deco_height, deco_height_max) : deco_height;
429 height = MYMIN(height, max_y - p.Y);
431 v3s16 em = vm->m_area.getExtent();
432 for (int i = start_y; i < height; i++) {
433 vm->m_area.add_y(em, vi, 1);
435 content_t c = vm->m_data[vi].getContent();
436 if (c != CONTENT_AIR && c != CONTENT_IGNORE)
439 vm->m_data[vi] = MapNode(c_place);
444 int DecoSimple::getHeight() {
445 return (deco_height_max > 0) ? deco_height_max : deco_height;
449 std::string DecoSimple::getName() {
454 ///////////////////////////////////////////////////////////////////////////////
469 // Returns Y one under area minimum if not found
470 s16 Mapgen::findGroundLevelFull(v2s16 p2d) {
471 v3s16 em = vm->m_area.getExtent();
472 s16 y_nodes_max = vm->m_area.MaxEdge.Y;
473 s16 y_nodes_min = vm->m_area.MinEdge.Y;
474 u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
477 for (y = y_nodes_max; y >= y_nodes_min; y--) {
478 MapNode &n = vm->m_data[i];
479 if (ndef->get(n).walkable)
482 vm->m_area.add_y(em, i, -1);
484 return (y >= y_nodes_min) ? y : y_nodes_min - 1;
488 s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) {
489 v3s16 em = vm->m_area.getExtent();
490 u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
493 for (y = ymax; y >= ymin; y--) {
494 MapNode &n = vm->m_data[i];
495 if (ndef->get(n).walkable)
498 vm->m_area.add_y(em, i, -1);
504 void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
508 //TimeTaker t("Mapgen::updateHeightmap", NULL, PRECISION_MICRO);
510 for (s16 z = nmin.Z; z <= nmax.Z; z++) {
511 for (s16 x = nmin.X; x <= nmax.X; x++) {
512 s16 y = findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
513 heightmap[index++] = y;
516 //printf("updateHeightmap: %dus\n", t.stop());
520 void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax) {
521 bool isliquid, wasliquid;
522 v3s16 em = vm->m_area.getExtent();
524 for (s16 z = nmin.Z; z <= nmax.Z; z++) {
525 for (s16 x = nmin.X; x <= nmax.X; x++) {
528 u32 i = vm->m_area.index(x, nmax.Y, z);
529 for (s16 y = nmax.Y; y >= nmin.Y; y--) {
530 isliquid = ndef->get(vm->m_data[i]).isLiquid();
532 // there was a change between liquid and nonliquid, add to queue
533 if (isliquid != wasliquid)
534 trans_liquid->push_back(v3s16(x, y, z));
536 wasliquid = isliquid;
537 vm->m_area.add_y(em, i, -1);
544 void Mapgen::setLighting(v3s16 nmin, v3s16 nmax, u8 light) {
545 ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
546 VoxelArea a(nmin, nmax);
548 for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) {
549 for (int y = a.MinEdge.Y; y <= a.MaxEdge.Y; y++) {
550 u32 i = vm->m_area.index(a.MinEdge.X, y, z);
551 for (int x = a.MinEdge.X; x <= a.MaxEdge.X; x++, i++)
552 vm->m_data[i].param1 = light;
558 void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light) {
559 if (light <= 1 || !a.contains(p))
562 u32 vi = vm->m_area.index(p);
563 MapNode &nn = vm->m_data[vi];
566 // should probably compare masked, but doesn't seem to make a difference
567 if (light <= nn.param1 || !ndef->get(nn).light_propagates)
572 lightSpread(a, p + v3s16(0, 0, 1), light);
573 lightSpread(a, p + v3s16(0, 1, 0), light);
574 lightSpread(a, p + v3s16(1, 0, 0), light);
575 lightSpread(a, p - v3s16(0, 0, 1), light);
576 lightSpread(a, p - v3s16(0, 1, 0), light);
577 lightSpread(a, p - v3s16(1, 0, 0), light);
581 void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax) {
582 VoxelArea a(nmin, nmax);
583 bool block_is_underground = (water_level >= nmax.Y);
585 ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
586 //TimeTaker t("updateLighting");
588 // first, send vertical rays of sunshine downward
589 v3s16 em = vm->m_area.getExtent();
590 for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) {
591 for (int x = a.MinEdge.X; x <= a.MaxEdge.X; x++) {
592 // see if we can get a light value from the overtop
593 u32 i = vm->m_area.index(x, a.MaxEdge.Y + 1, z);
594 if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
595 if (block_is_underground)
597 } else if ((vm->m_data[i].param1 & 0x0F) != LIGHT_SUN) {
600 vm->m_area.add_y(em, i, -1);
602 for (int y = a.MaxEdge.Y; y >= a.MinEdge.Y; y--) {
603 MapNode &n = vm->m_data[i];
604 if (!ndef->get(n).sunlight_propagates)
606 n.param1 = LIGHT_SUN;
607 vm->m_area.add_y(em, i, -1);
612 // now spread the sunlight and light up any sources
613 for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) {
614 for (int y = a.MinEdge.Y; y <= a.MaxEdge.Y; y++) {
615 u32 i = vm->m_area.index(a.MinEdge.X, y, z);
616 for (int x = a.MinEdge.X; x <= a.MaxEdge.X; x++, i++) {
617 MapNode &n = vm->m_data[i];
618 if (n.getContent() == CONTENT_IGNORE ||
619 !ndef->get(n).light_propagates)
622 u8 light_produced = ndef->get(n).light_source & 0x0F;
624 n.param1 = light_produced;
626 u8 light = n.param1 & 0x0F;
628 lightSpread(a, v3s16(x, y, z + 1), light);
629 lightSpread(a, v3s16(x, y + 1, z ), light);
630 lightSpread(a, v3s16(x + 1, y, z ), light);
631 lightSpread(a, v3s16(x, y, z - 1), light);
632 lightSpread(a, v3s16(x, y - 1, z ), light);
633 lightSpread(a, v3s16(x - 1, y, z ), light);
639 //printf("updateLighting: %dms\n", t.stop());
643 void Mapgen::calcLightingOld(v3s16 nmin, v3s16 nmax) {
644 enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT};
645 VoxelArea a(nmin, nmax);
646 bool block_is_underground = (water_level > nmax.Y);
647 bool sunlight = !block_is_underground;
649 ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
651 for (int i = 0; i < 2; i++) {
652 enum LightBank bank = banks[i];
653 std::set<v3s16> light_sources;
654 std::map<v3s16, u8> unlight_from;
656 voxalgo::clearLightAndCollectSources(*vm, a, bank, ndef,
657 light_sources, unlight_from);
658 voxalgo::propagateSunlight(*vm, a, sunlight, light_sources, ndef);
660 vm->unspreadLight(bank, unlight_from, light_sources, ndef);
661 vm->spreadLight(bank, light_sources, ndef);
666 //////////////////////// Mapgen V6 parameter read/write
668 bool MapgenV6Params::readParams(Settings *settings) {
669 freq_desert = settings->getFloat("mgv6_freq_desert");
670 freq_beach = settings->getFloat("mgv6_freq_beach");
673 settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base) &&
674 settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher) &&
675 settings->getNoiseParams("mgv6_np_steepness", np_steepness) &&
676 settings->getNoiseParams("mgv6_np_height_select", np_height_select) &&
677 settings->getNoiseParams("mgv6_np_mud", np_mud) &&
678 settings->getNoiseParams("mgv6_np_beach", np_beach) &&
679 settings->getNoiseParams("mgv6_np_biome", np_biome) &&
680 settings->getNoiseParams("mgv6_np_cave", np_cave) &&
681 settings->getNoiseParams("mgv6_np_humidity", np_humidity) &&
682 settings->getNoiseParams("mgv6_np_trees", np_trees) &&
683 settings->getNoiseParams("mgv6_np_apple_trees", np_apple_trees);
688 void MapgenV6Params::writeParams(Settings *settings) {
689 settings->setFloat("mgv6_freq_desert", freq_desert);
690 settings->setFloat("mgv6_freq_beach", freq_beach);
692 settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base);
693 settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
694 settings->setNoiseParams("mgv6_np_steepness", np_steepness);
695 settings->setNoiseParams("mgv6_np_height_select", np_height_select);
696 settings->setNoiseParams("mgv6_np_mud", np_mud);
697 settings->setNoiseParams("mgv6_np_beach", np_beach);
698 settings->setNoiseParams("mgv6_np_biome", np_biome);
699 settings->setNoiseParams("mgv6_np_cave", np_cave);
700 settings->setNoiseParams("mgv6_np_humidity", np_humidity);
701 settings->setNoiseParams("mgv6_np_trees", np_trees);
702 settings->setNoiseParams("mgv6_np_apple_trees", np_apple_trees);
706 bool MapgenV7Params::readParams(Settings *settings) {
708 settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base) &&
709 settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt) &&
710 settings->getNoiseParams("mgv7_np_terrain_mod", np_terrain_mod) &&
711 settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist) &&
712 settings->getNoiseParams("mgv7_np_height_select", np_height_select) &&
713 settings->getNoiseParams("mgv7_np_ridge", np_ridge);
718 void MapgenV7Params::writeParams(Settings *settings) {
719 settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
720 settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
721 settings->setNoiseParams("mgv7_np_terrain_mod", np_terrain_mod);
722 settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
723 settings->setNoiseParams("mgv7_np_height_select", np_height_select);
724 settings->setNoiseParams("mgv7_np_ridge", np_ridge);
728 /////////////////////////////////// legacy static functions for farmesh
730 s16 Mapgen::find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision) {
731 //just need to return something
737 bool Mapgen::get_have_beach(u64 seed, v2s16 p2d) {
738 double sandnoise = noise2d_perlin(
739 0.2+(float)p2d.X/250, 0.7+(float)p2d.Y/250,
740 seed+59420, 3, 0.50);
742 return (sandnoise > 0.15);
746 double Mapgen::tree_amount_2d(u64 seed, v2s16 p) {
747 double noise = noise2d_perlin(
748 0.5+(float)p.X/125, 0.5+(float)p.Y/125,
750 double zeroval = -0.39;
754 return 0.04 * (noise-zeroval) / (1.0-zeroval);