PDA

View Full Version : Region Module


Anpheus
03-30-2005, 16:41
I was unable to get Borland Delphi to work so, I have an idea for a module:

Region Module-

Enables area-based functions to be called when entities of certain types have entered the region.


flags for region_complement, region_union, region_change
a - Following arguments represent pairs of two vertices
b - Following arguments represent ids
c - Take complement of input value region(s) (Inverted/complement regions cannot (easily) be used with Union or Intersection, so either it can error with this flag or return false/0.)

flags for region_add:
a - Option to call function each frame is within the region.
b - Option to call function every frame a player enters or leaves.

Natives-
region_add(id, const function[], Float:vertex_a[3], Float:vertex_b[3], flags[] = "")
region_destroy(id)
region_union(id, flags[] = "", ...)
region_intersection(id, flags[] = "", ...)
region_complement(id, flags[] = "", ...)
region_exists(id)
region_change(id, flags[] = "", ...)
region_shape(id) //Returns one of the two constants.
region_vertices(id, Float:vertex_a[3], Float:vertex_b[3])
region_size(id, Float:size[3]) //Returns the product of x y and z as well.
region_origin(id, Float:origin[3])

Constants-
enum { //Shape values
REGION_OCTAHEDRON //Cubic, the 'inside' is considered to be bounded by a finite space between pairs of planes on the x, y, and z axis.
REGION_INVERTED //Anything 'outside' the area bounded by the planes between the defined vertices area is considered in the cube.
}
enum { //Status values
ENTITY_REG_IN = 1<<0 //Applies while an entity is in the region
ENTITY_REG_ENTER = 1<<1 //Applies
ENTITY_REG_LEAVE = 1<<2 //Used
}

Region forward arguments: id, status


Update: Added region_intersection. region_union would be more difficult to implement so I don't believe it would be a requirement.

Twilight Suzuka
03-30-2005, 17:32
if I could get MM functions running in my module, I'd do this.

Anpheus
03-30-2005, 17:51
There are a few ways to do this (obviously.) And there are most likely even faster algorithms that would never be implemented here.


But basically the two methods I thought of, in order of efficiency or simplicity:

A) Simply check the origin of every entity or just player every frame. Eegad!

B) Make 1 unit wide solid walls that define the planes, but space them out so that there are six inside planes, and six outside. Make it so that a player must contact one to leave or enter the group, but can never contact both. (i.e.: Seperated by 33 units) Then hook pfn_touch and whenever the inside barriers or outside barriers are contacted, it is blocked (hopefully this would make them nontangible) and then call the function.

There wold have to be an array associated with each region to determine which entities are 'inside' and which are 'outside'

Via either method it should be noted that if >1/2 of the entities in the game exist within the region, the shape should be marked 'inverted' and then the entity list should be redone likewise. This would keep the list of entities within each entity down to a minimum.

And Sukuza, I'm glad you're thinking about this. I'm sure you well know that this would be invaluable for RP plugins. It would also make area-specific physics values easy.