Not logged inOpenClonk Forum
Up Topic General / Feedback and Ideas / Collection+Entry=ControlArea
- - By Carli [de] Date 2009-09-19 18:51
What about transforming Collection and Entry to a general ControlArea which means you can have other, additional Areas, too (f.e. more than one Entry in Ship or multible Collection Areas for a Bulldoozer)....

i.e. you need a type what Event should activate thes Area and you need a bounding of this area and you need some callbacks like onEnterControlArea and onLeaveControlArea.
Parent - By Carli [de] Date 2009-09-24 15:34
I made a change where the places in the code were marked where there is something to change.
Maybe anyone could say if we could drop the downwards compatibility with the OCFs or how we could find a way how to define it in the definition-script.
Attachment: ControlAreaIdeas.diff (3k)
Parent - - By Clonk-Karl [us] Date 2009-09-24 23:32
I don't like the name ControlArea very much. It's not like the area controls anything. What about InteractionArea?

Are these areas supposed to be added to an object (definition?) via script?
Reply
Parent - - By Carli [de] Date 2009-09-25 09:41
I think they should be added in the init script or when the door is opened/closed

InteractionArea.......baybe you could find a shorter word
Parent - By Clonk-Karl [us] Date 2009-09-25 15:11
I think we should prefer explicitness over shortness.
Reply
Parent - - By Newton [de] Date 2009-09-25 00:11 Edited 2009-09-25 13:20
Now that you made the effort to even offer a implementation I feel the need to at least comment on it:

The examples you gave are not really convincing as both are very special. Let me give another example for an InteractionArea - NPCs. But this has been always successfully done with Entrance-Areas so I don't understand why we need a more generalized model to handle events like Entrance and Collection zones.
I am against over-generalization that
  1. no one uses: we don't code interfaces for special cases whose features are not used in 99% of all cases. The interfaces should be defined to fit the normal requirements. Now with the old Entrance-zone code, one can still code something special like the NPCs I mentioned. And...

  2. makes the standard usage more complicated: Defining Entrance=10,10,80,80 is certainly easier than defining a control zone with the right callbacks and coding, even if there is some pre-defined door-Entrance-object from which objects can inherit.

So, to sum it up, I don't see much sense in this patch. I approve that you show so much motivation to improve OpenClonk but before you take the trouble to implement stuff, you should wait for some feedback on that. Just an advice to not waste time.
Parent - - By Clonk-Karl [us] Date 2009-09-25 00:59

> The examples you gave are not really convincing as both are very special.


It might prove useful for objects like the submarine where the collection area changes when it turns (although we could also think about always flipping entrance&collection depending on an object's dir).

> But this has been always successfully done with Entrance-Areas


I would certainly not be sad if we get rid of this hack.

> we don't code interfaces for special cases whose features are not used in 99% of all cases.


If there is somebody doing the work (and maintaining it), why not? As long as it doesn't get in the way for others I don't see a problem there.

> makes the standard usage more complicated: Defining Entrance=10,10,80,80 is certainly easier than defining a control zone with the right callbacks and coding, even if there is some pre-defined door-Entrance-object from which objects can inherit.


Nobody says that the Entrance definition in the DefCore needs to go away. It can just do something different internally, such as creating a default InteractionArea.

> So, to sum it up, I don't see much sense in this patch. I approve that you show so much motivation to improve OpenClonk but before you take the trouble to implement stuff, you should wait for some feedback on that. Just an advice to not waste time.


There is no implementation yet. Just a patch marking locations in the code where changes need to be applied to make this happen. So what you describe here is actually just what Carli did. Also, I think that having a patch before having discussed things in every detail is not necessarily bad - it gives a basis for the discussion, and it might help making clear one's ideas.
Reply
Parent - By Carli [de] Date 2009-09-25 09:47

>It might prove useful for objects like the submarine where the collection area changes when it turns (although we could also think about always flipping entrance&collection depending on an object's dir).


right. one can replace entrance-areas, you need no 20 different callbacks to close/open entrances/collections, you just reset the array of Areas

>There is no implementation yet. Just a patch marking locations in the code where changes need to be applied to make this happen. So what you describe here is actually just what Carli did. Also, I think that having a patch before having discussed things in every detail is not necessarily bad - it gives a basis for the discussion, and it might help making clear one's ideas.


yes i thaught it would be better to discuss before I implement something that should have p.e. an oher name or sth.
Parent - By Newton [de] Date 2009-09-25 12:28

>There is no implementation yet. Just a patch marking locations in the code where changes need to be applied to make this happen. So what you describe here is actually just what Carli did


Ah, ok.
Parent - By boni [at] Date 2009-09-26 15:57

>It might prove useful for objects like the submarine where the collection area changes when it turns (although we could also think about always flipping entrance&collection depending on an object's dir).


OT: I'd also like to see Vertices with that feature. :] @flipping
Parent - - By Carli [de] Date 2009-09-25 09:52

>I am against over-generalization that


It is not an over-generalizing.
But an area which calls a certain callback when an object with a fixed OCF enters the area and it makes a callback whether the object should enter this container is, i think, a bit too specialized. What if you want to invent an object that collects not the OCF_Collectible but the OCF_Vehicle? You have to work with one-frame-timers, helper objects etc.

For downwards compatibility we could, like Clonk-Karl said, generate dummy-Areas, one for Collection, one for Entrance (but my plan was to replace them.......)
Parent - By Newton [de] Date 2009-09-25 13:26

>What if you want to invent an object that collects not the OCF_Collectible but the OCF_Vehicle? [...]


Like what? Thats my whole point: I think interfaces should be designed to fit the normal requirements. As long as there is a back door for special requirements like your example (-> Timer call or effect), it's fine.
Parent - By Günther [de] Date 2009-09-25 16:18
Multiple Entrances would certainly be used. The amount of code needed to work around their lack is astounding. Multiple Collection areas are not really needed, the submarine works just fine with RejectCollect. And if somebody gets around to convert the Collection area to a property, or implements flipping them as ck suggested, even the submarine doesn't need special area code in it's script.

On the other hand, more flexible mouse behavior could be useful. Hardcoded tree chopping for example is not the most elegant solution.
Reply
Parent - - By Clonkonaut [de] Date 2009-09-26 19:17 Edited 2009-09-26 19:20
I kinda like the idea. So I've thought about a concrete concept:
You can define such areas (the name doesn't matter. Areas in Clonk are called 'zones', so ControlZone, ActionZone, TriggerZone, InteractionZone, whatever. I call them ControlZone) with:
int AddControlZone(int iX, int iY, int iWidth, int iHeight, int OCF, string EntryCallback, string ExitCallback);
The return value is the zone's unique id (unique for every object) to manipulate the zone via Set/ChangeControlZone(int ID, int iX, int iY, int iWidth, int iHeight, int OCF, string EntryCallback, string ExitCallback); and RemoveControlZone(int ID);

I think the function is almost self-explanatory. Whenever an object with the matching OCF enters the zone, the entry callback is called, whenever it exits, the exit callback (both optional parameters, you may leave out the exit callback e.g.).
CollectionZones would be replaced with CollectionZone.c4d. Objects may inherited this interface and create the zones via Add/SetCollectionZone(int iX, int iY, int iWidth, int iHeight); (private function of CollectionZone.c4d) or, if you want to stick to the 'DefCore' solution, CollectionZone.c4d may define its own Initialize where reading out the values from the object's proplist. The entry callback of CollectionZone.c4d calls RejectCollect and Collection aftering entering.
This may replace at least CollectionZones and TransferZones. Beyond that a good amount of findobject-loops would become obsolete. Sample applications are scenario script progress, your homing missile launcher (or the fireball spell? But moving ControlZone may overcomplicate everything).

At all, not a must-have but nice to have.

/edit
Of course, this is no solution to replace EntranceZone or similar.
Reply
Parent - By Newton [de] Date 2009-09-26 23:51 Edited 2009-09-26 23:56
Yes, this is the interface which I imagined too. However, I'd replace int OCF with array Criteria in the fashion of FindObject.

The problem where Carli felt offended and left the discussion was the issue with the timer. Most findobject loops are NOT not called each and every frame - because of thoughts about speed. Now of course it is possible to add another parameter to the control zone. But I am still against this because with that we hide the real complexity from the developer so that he does not directly see anymore how expensive this really is. Additionally, he has less control over how will be searched - e.g. he always needs to specifiy a box and can not specify a maximum distance or a point.
And for what? For not having to write this
for(var obj = FindObjects(mycriteria)) { dosomething(obj); } in a timer call or effect
but this
AddControlZone(boxx, boxxy, boxwidth, boxheight, mycriteria, "dosomething", "dosomething_orperhapsnot");

The actual gain is in my opinion a very small or none.
Parent - - By Sven2 [de] Date 2009-09-25 13:06
You're talking about two different kinds of areas here.

You could replace the object CrossCheck with a more flexible solution where you would define areas and conditions. Currently, this includes collection, incineration, fight check and tumble check (clonks hit by rocks). Many objects such as arrows, traps, floor switches, monsters, etc. emulate the behavior by script. It's not terribly important, because scripts can do just the same thing as the engine here, so it would be an optimization. I'm also not sure whether a leave callback is needed, as it involves a lot of bookkeeping and is rarely needed.

Entrance areas are different because they do not actively search for objects, but are usually being searched for. They're also special because they would need engine internal support if you want to allow mouse interaction with them.

So, imo, if you want to implement ControlAreas, you should focus on areas that are actually controlled. They would have attributes like the mouse cursor set when you hover the mouse over them and callbacks for mouse clicks, drag+drop, etc.

A generalization of collection areas as an optimization may be implemented, too, but I wouldn't call them ControlArea. They might derive from a common Area class, of course, and may even share some script functions (finding areas by point, rect, etc.). Another question is whether we should allow non-rectangular areas.
Parent - By Carli [de] Date 2009-09-25 14:57
you're right. I'll wait for some ideas that make sense to implement (f.e. an exactly idea of collection areas etc.) but it makes no sense to merge entrance with collection
Parent - - By Luchs [de] Date 2009-09-25 17:28
An area for grabbing would also be nice, for example for buildings with special parts for controlling in the graphic.
Parent - - By Carli [de] Date 2009-09-26 09:03 Edited 2009-09-26 14:34
Summary:
- Entrance will stay Entrance
- Collection, traps, grabbing areas, incineration, fight check, tumble check etc. will get a new interface called Area
- an Area can be accessed as an array of objects
- there are callbacks when new objects enter or leave the area (only regarded when callbacks available, also notice objects that "fly through" by an enter and an exit in one frame)
- the object in the area can ask whether it is in such area (f.e. when you press double-down) and cann invoke a callback for the area (f.e. "i pressed double down")

Here some things where you can use it:
- waiting for clonks at the elevator
- traps
- goals where you have to bring an object to a certain place
- AIs where the enemy detects who is in his range
and much more
Parent - - By Zapper [de] Date 2009-09-26 11:05

>- there are callbacks when new objects enter or leave the area


Sounds like unnecessary overhead.

>Here some things where you can use it:


None of your examples sound as if the current situation there would be improved with areas.
Parent - - By Carli [de] Date 2009-09-26 14:38

>Sounds like unnecessary overhead.


it could'nt be more overhead than in the alternative solutions (helper objects, one frame timer)

>None of your examples sound as if the current situation there would be improved with areas.


^^same like above
Parent - - By Newton [de] Date 2009-09-26 14:59 Edited 2009-09-26 15:04

>>None of your examples sound as if the current situation there would be improved with areas.
>it could'nt be more overhead than in the alternative solutions (helper objects, one frame timer)


So the reason you want to implement this is because it doesn't make things worse??

Edit: It might be easier to use for the c4script developers and streamlined in the engine code (=faster, more reliable), especially for those fast objects that are out of the area before the frame ends. Big "might" here as it strongly depends on the quality of the implementation of the Area code in the engine. Anyway, I would like to see an example of how the interface would look like.
Parent - By Carli [de] Date 2009-09-26 15:10
i want to make areas be easier to script and i want to have a performance improve
Parent - - By Zapper [de] Date 2009-09-26 15:31 Edited 2009-09-26 16:20

>^^same like above


No. Neither the elevator, a trap, a goal nor an AI would ever need a 1-Frame-Timer there. If you really had a 1-frame-timer somewhere your area system could be as fast. But I cannot imagine any situation now where it would be really faster. (Except for use as a collection area where it would be easier with those areas)
Parent - By Carli [de] Date 2009-09-26 15:42
when you don't want the feature, i won't code the future
bye i have to do with gwX2
Parent - - By Newton [de] Date 2009-09-26 12:04
What about a hit check of fast objects like e.g. arrows? In one frame, the arrow is left of the area, on the next frame it is already right of that area.
Parent - - By Carli [de] Date 2009-09-26 14:33
that's the weird physic of Clonk. gwX had a better solution to stretch objects to the length of ther speed and then tests the intersection.

-- post edited
Parent - - By Newton [de] Date 2009-09-26 14:57
Stretch them to the length of their speed? This is an odd solution. Why not create a line segment from the last position to the current position and check any intersections with the bounding boxes (width*height) of objects that lie inside the bounding box of the line segment?
Parent - - By Carli [de] Date 2009-09-26 15:02
that's not precious enough
it's an easy raytracing algorithm to calculate the continous collision of two spheres (gwX uses spheres as vertices, in OC we do really need lines, you're right)
Parent - - By Newton [de] Date 2009-09-26 15:04

>precious


precious? What do you mean?
Parent - By Clonkonaut [de] Date 2009-09-26 16:09
precise
Reply
Parent - - By MrBeast [de] Date 2009-09-26 15:09
You don't need such a high precision for that.
Reply
Parent - - By Carli [de] Date 2009-09-26 15:18
you don't know. The objects would fall through the gwX-World. in OC it may work, you're right
Parent - - By MrBeast [de] Date 2009-09-26 15:31
We are speaking about area-checks...
Reply
Parent - - By Carli [de] Date 2009-09-26 15:41
i said in OC, lines traced make sense, see post on trunk root
Parent - - By MrBeast [de] Date 2009-09-26 15:52
You havn't talked about area-checks in gwX so the comparison makes no sense.
Reply
Parent - By Carli [de] Date 2009-09-27 07:17
the idea of area checks with high speed objects is to trace the movement line of the object. That is what exactly the whole gwX Engine does to calculate Physics with the difference that gwX uses spheres as vertices and OC uses points instead.
Parent - - By Sven2 [de] Date 2009-09-26 23:46
You know, it's easy to calculate if (and when) two spheres of known position and velocity collide.

Be x0(t)=p0+v0*t the position of object one; be x1(t)=p1+v1*t the position of object two. The distance of the two is D(t)=||x0(t)-x1(t)||. The minimum distance is at d/dt D(t) = 0. Derive and resolve t (excluding any special cases of zero velocity and such here):

D(t) = sqrt((p0x-p1x+(v0x-v1x)*t )^2 + (p0y-p1y+(v0y-v1y)*t )^2)

d/dt D(t) = 1/sqrt((p0x-p1x+(v0x-v1x)*t )^2 + (p0y-p1y+(v0y-v1y)*t )^2) * (2*(p0x-p1x+(v0x-v1x)*t )*(v0x-v1x) + 2*(p0y-p1y+(v0y-v1y)*t )*(v0y-v1y)) = 0
(p0x-p1x+(v0x-v1x)*t )*(v0x-v1x) + (p0y-p1y+(v0y-v1y)*t )*(v0y-v1y) = 0
(p0x-p1x)*(v0x-v1x) + (p0y-p1y)*(v0y-v1y) = -t * ((v0x-v1x)^2+(v0y-v1y)^2)
t = -((p0x-p1x)*(v0x-v1x) + (p0y-p1y)*(v0y-v1y)) / ((v0x-v1x)^2+(v0y-v1y)^2)

This gives you the time t at which the distance of the two objects is minimal. Clamp t to 0-1 (for the duration of 1 frame) and check if D(t) is smaller than the sum of the two sphere's radius.

(math not double checked, but you should get the point)
Parent - - By Clonk-Karl [us] Date 2009-09-27 01:14
Minimizing the squared distance D(t)^2 makes the math even easier, probably.
Reply
Parent - - By Sven2 [de] Date 2009-09-27 09:11 Edited 2009-09-27 09:17
No, since sqrt derived just adds a denominator (1/sqrt(...)) which is discarded anyway.

Question is, of course, whether all this is really necessary. The inaccuracies of doing a simple per-frame overlap check are rarely noticed.
Parent - - By Carli [de] Date 2009-09-27 14:06
No, you have the ability to calculate high speed bullets without making more than one overlap test (remember: when you simulate a bullet you have to make PathLengthThisFrame()/BulletLength() iterations to not overjump a target. this technique is very weird (and a bit more complex than a tracing algorithm))
Parent - - By Sven2 [de] Date 2009-09-27 22:31
You don't "have" to do this. You could just accept that very fast shots sometimes fly past Clonks.
Parent - By Carli [de] Date 2009-09-28 13:14
no, it would annoy people who want to make a hazard pack
Parent - - By Clonk-Karl [us] Date 2009-09-28 16:09

> Question is, of course, whether all this is really necessary. The inaccuracies of doing a simple per-frame overlap check are rarely noticed.


The problem with it is the complexity of implementation, not necessarily performance issues, right? I'd actually like if we get this right, at least optionally. Correct me if I'm wrong, but I can imagine that currently quite a few object packs implement such a more accurate check themselves. I might also be possible to stop people complaining about (not) being hit by fast moving objects this way.
Reply
Parent - - By Zapper [de] Date 2009-09-28 17:06

>Correct me if I'm wrong, but I can imagine that currently quite a few object packs implement such a more accurate check themselves.


Yupp, but less for simulating being hit by a mass (with tumbling and stuff) and more for doing some own damaging. So these objects are actually C4D_Vehicle and wouldn't really benefit from an increased accuracy there ( - still, some objects don't. Would be cool to have cannons as a deadly weapon against clonks as well :)  )
Parent - - By Clonk-Karl [us] Date 2009-09-28 17:41

> So these objects are actually C4D_Vehicle and wouldn't really benefit from an increased accuracy there


But they would if they could define a custom Area as proposed.
Reply
Parent - By Zapper [de] Date 2009-09-28 18:08 Edited 2009-09-28 18:11
Oh, wouldn't they have to define such an area for the objects that would be to be hit? (that is: wouldn't the movement of an object A not just check for intersections with areas of other objects?). And if not: The object would still have to post-step through the line between the last frame and the current to check for the real colliding point (since even if the check for intersection was made: the object A would still have flewn through the object B when the callback would be called in A) (realising now that the position could easily be passed to that callback). But nevertheless: I don't really see any performance improvement in using those areas instead of a Find_OnLine/Find_AtPoint every frame - I have to grant that it would be "easier" for the scripter to use, though
Parent - By Carli [de] Date 2009-09-27 07:14
I know, the same you will find in the gwX Source code. (in an optimized way)
Parent - By MrBeast [de] Date 2009-09-26 14:55
I think it wouldn't be a problem to implement a fly-through-check.
Reply
Parent - By Newton [de] Date 2009-09-26 14:59

>- Collection, traps, grabbing areas, incineration, fight check, tumble check etc. will get a new interface called Area


I think grabbing areas fall into the same category as entrance as they are inactive and have to be activated/used by the clonk.
Up Topic General / Feedback and Ideas / Collection+Entry=ControlArea

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill