Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VoxelArea support #34

Open
S-S-X opened this issue Oct 21, 2021 · 2 comments · May be fixed by #84
Open

Add VoxelArea support #34

S-S-X opened this issue Oct 21, 2021 · 2 comments · May be fixed by #84
Labels
enhancement New feature or request in-latest-docker Included with latest docker images, might not yet be available elsewhere

Comments

@S-S-X
Copy link
Owner

S-S-X commented Oct 21, 2021

A helper class for voxel areas.
It can be created via VoxelArea:new{MinEdge = pmin, MaxEdge = pmax}.
The coordinates are inclusive, like most other things in Minetest.

Methods

  • getExtent(): returns a 3D vector containing the size of the area formed by
    MinEdge and MaxEdge.
  • getVolume(): returns the volume of the area formed by MinEdge and
    MaxEdge.
  • index(x, y, z): returns the index of an absolute position in a flat array
    starting at 1.
    • x, y and z must be integers to avoid an incorrect index result.
    • The position (x, y, z) is not checked for being inside the area volume,
      being outside can cause an incorrect index result.
    • Useful for things like VoxelManip, raw Schematic specifiers,
      PerlinNoiseMap:get2d/3dMap, and so on.
  • indexp(p): same functionality as index(x, y, z) but takes a vector.
    • As with index(x, y, z), the components of p must be integers, and p
      is not checked for being inside the area volume.
  • position(i): returns the absolute position vector corresponding to index
    i.
  • contains(x, y, z): check if (x,y,z) is inside area formed by
    MinEdge and MaxEdge.
  • containsp(p): same as above, except takes a vector
  • containsi(i): same as above, except takes an index i
  • iter(minx, miny, minz, maxx, maxy, maxz): returns an iterator that returns
    indices.
    • from (minx,miny,minz) to (maxx,maxy,maxz) in the order of
      [z [y [x]]].
  • iterp(minp, maxp): same as above, except takes a vector
@S-S-X S-S-X added the enhancement New feature or request label Oct 21, 2021
@S-S-X S-S-X added the good first issue Good for newcomers label Oct 23, 2021
@S-S-X
Copy link
Owner Author

S-S-X commented Oct 28, 2021

-- mapnode.h
-- Built-in Content IDs (for use with VoxelManip API)
core.CONTENT_UNKNOWN = 125
core.CONTENT_AIR     = 126
core.CONTENT_IGNORE  = 127

Content id allocation
https://github.com/minetest/minetest/blob/8dfeba02b9f084ddd52090ccd906534200f468b3/src/nodedef.cpp#L1161-L1179

// returns CONTENT_IGNORE if no free ID found
content_t NodeDefManager::allocateId()
{
	for (content_t id = m_next_id;
			id >= m_next_id; // overflow?
			++id) {
		while (id >= m_content_features.size()) {
			m_content_features.emplace_back();
		}
		const ContentFeatures &f = m_content_features[id];
		if (f.name.empty()) {
			m_next_id = id + 1;
			return id;
		}
	}
	// If we arrive here, an overflow occurred in id.
	// That means no ID was found
	return CONTENT_IGNORE;
}

Variable m_next_id is reset to zero. First id returned by allocateId is 1 effectively making content id 1 based.

@S-S-X
Copy link
Owner Author

S-S-X commented Jun 11, 2022

This should probably be using VoxelArea from engine core Lua libraries, VoxelArea class itself is just Lua helper and #74 already pulls that in when specified version is not "mineunit".

Having tests from #84 would probably still be useful even while it is engine library, tests would still allow some verification about Mineunit behavior.

Directory structure and loading of Minetest engine Lua libraries should be made better and more correct, when those were first added there was no plans to actually support many engine features.

Now things have changed a bit and a lot of Minetest c++ side things are already implemented. Mineunit is actually able to load significant amount of core Lua scripts and even pulls those directly from Minetest repo when asked to do so.

@S-S-X S-S-X added this to Mineunit Jan 11, 2024
@S-S-X S-S-X added in-latest-docker Included with latest docker images, might not yet be available elsewhere and removed good first issue Good for newcomers labels Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in-latest-docker Included with latest docker images, might not yet be available elsewhere
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

1 participant