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);
}