Accessing backdrops from extensions
Knowing how fun it is to access objects in the game, I suppose this may be pushing it, but perhaps there is a way to do this.
Basically, I would like to do either (any will work) of the following from within an extension:
1. Check whether a given coordinate lies on an obstacle or not.
2. Get a list of obstacles with their position/image data.
I know these must be stored somewhere so that collisions can be tested with active objects, but I don't know if we can reach that data structure.
Re: Accessing backdrops from extensions
You can do #1 already with the StoryBoard object
Re: Accessing backdrops from extensions
Quote:
Originally Posted by Mokhtar
from within an extension:
Re: Accessing backdrops from extensions
As StephenL said :)
I think the StoryBoard object is an internal object so it may have more privileges than extensions. But if the same mechanism is accessible to extensions, then that would be great.
Re: Accessing backdrops from extensions
Oh, I thought he was looking for an extension that would do that. Sorry for my misunderstanding :crazy:
Re: Accessing backdrops from extensions
That's alright. No problem :)
Re: Accessing backdrops from extensions
Storyboard Object? What the heck is that? I don't have it in my MMF -_- Cause I understand that you're not talking about Storyboard Controls.
Re: Accessing backdrops from extensions
Quote:
Originally Posted by Fanotherpg
Storyboard Object? What the heck is that? I don't have it in my MMF
Of course you do and you probably use it in every application!
Re: Accessing backdrops from extensions
Quote:
Originally Posted by Fanotherpg
Storyboard Object? What the heck is that? I don't have it in my MMF
The object is called the Storyboard Object, but it has storyboard controls. Big difference there. ;)
Re: Accessing backdrops from extensions
I've done these in the XLua MMFI extension (it supports a wide array of collision detection). Here's some relevant code you can try and tease apart. If you only care about Layer 0 (the collision mask), it's very easy and short. For obstacles on all layers, you need all this extra crap.
SpriteSupport is just a container that holds an npSpr and returns bits of its internal data ... I've included the relevant snippets.
Code:
typedef std::list<void*> GenList;
int SpriteSupport::GetFlags () {
return GetSpriteFlags(_rh->rh4.rh4Mv->mvIdEditWin, _spr);
}
LPLO SpriteSupport::GetLO () {
return (LPLO)GetSpriteExtra(_rh->rh4.rh4Mv->mvIdEditWin, _spr);
}
...
void Collisions::SpriteListByPoint (GenList& list, LPRH rh, int x, int y, int layer, int flag) {
npWin win = rh->rh4.rh4Mv->mvIdEditWin;
npSpr spr = 0;
x = x - rh->rh3.rh3DisplayX;
y = y - rh->rh3.rh3DisplayY;
while ((spr = SpriteCol_TestPoint(win, spr, layer, x, y, flag)) != 0) {
list.push_back(spr);
}
}
void Collisions::SpritesToBackdrops (GenList& list, LPRH rh, int layer) {
for (GenList::iterator it = list.begin(); it != list.end(); ) {
npSpr spr = (npSpr)*it;
SpriteSupport ss(rh, spr);
// Get rid of non-backgrounds
DWORD flags = ss.GetFlags();
if (!(flags & SF_BACKGROUND) || !(flags & SF_OBSTACLE)) {
it = list.erase(it);
continue;
}
// Switch to LOs
LPLO lo = ss.GetLO();
if (!lo) {
it = list.erase(it);
continue;
}
else if (layer != LAYER_ALL && lo->loLayer != layer) {
it = list.erase(it);
continue;
}
else {
*it = lo;
it++;
}
}
}
void Collisions::BackdropListByPoint (GenList& list, LPRH rh, int x, int y, int layer) {
SpriteListByPoint(list, rh, x, y, layer, SCF_BACKGROUND);
SpritesToBackdrops(list, rh, layer);
}
int Collisions::BackdropTestPoint (LPRH rh, int x, int y, int layer) {
npWin win = rh->rh4.rh4Mv->mvIdEditWin;
int xadj = x - rh->rh3.rh3DisplayX;
int yadj = y - rh->rh3.rh3DisplayX;
if (layer == LAYER_ALL || layer == 0) {
if (ColMask_TestPoint(win, xadj, yadj, 0))
return 1;
if (layer == 0)
return 0;
}
GenList list;
BackdropListByPoint(list, rh, x, y, layer);
return (list.size() > 0);
}
Re: Accessing backdrops from extensions
I do not see where do you get the GenList list from MMF? Is it somewhere in SpriteCol_TestPoint?
Quote:
Originally Posted by Retriever2
If you only care about Layer 0 (the collision mask), it's very easy and short
What's the short version in this case?
Thanks for the info :)
Re: Accessing backdrops from extensions
So you meant storyboard control object :)
Re: Accessing backdrops from extensions
Quote:
Originally Posted by Mokhtar
I do not see where do you get the GenList list from MMF? Is it somewhere in SpriteCol_TestPoint?
Quote:
Originally Posted by Retriever2
If you only care about Layer 0 (the collision mask), it's very easy and short
What's the short version in this case?
Thanks for the info :)
Very first line: typedef std::list<void*> GenList;
It's just an STL list of void pointers.
If you only care about layer 0, then:
Code:
int Collisions::BackdropTestPoint (LPRH rh, int x, int y, int layer) {
npWin win = rh->rh4.rh4Mv->mvIdEditWin;
int xadj = x - rh->rh3.rh3DisplayX;
int yadj = y - rh->rh3.rh3DisplayX;
if (ColMask_TestPoint(win, xadj, yadj, 0))
return 1;
return 0;
}
However, I think there is also a callback function in rh4 that will also do the point test, and that has a stronger guarantee of working across runtimes.
callColMaskTestPoint(hoPtr, x, y, nLayer, plan)
Re: Accessing backdrops from extensions
Perfect, the short version should be sufficient, I'll give it a shot :)
Quote:
Originally Posted by Retriever2
Very first line: typedef std::list<void*> GenList;
It's just an STL list of void pointers.
Yes, I meant where does it gets populated with the actual objects? There must be some call somewhere to fill it.
Re: Accessing backdrops from extensions
In SpriteListByPoint, there is a list.push_back(spr) in the while loop -- that populates it. It's passed by reference up the call stack.
The SpriteCol_TestPoint function in cnpdll will find npSpr objects whether they are bound to objects, or to backdrops, hence the need for a filtering step.
Re: Accessing backdrops from extensions
Quote:
Originally Posted by Retriever2
int yadj = y - rh->rh3.rh3DisplayX;
I think you got a typo there. Shouldnt the last letter be Y not X? :)
Re: Accessing backdrops from extensions
Yes, you are correct .. I guess that means I have a bug I also need to fix in the library :)
Re: Accessing backdrops from extensions
Oh thanks Retriever2, I guess that's just what I need for the Surface object.