Pages: 1
  Print  
Author Topic: Instance Interface How-to  (Read 17143 times)
Offline (Male) Josh @ Dreamland
Posted on: September 09, 2010, 12:40:21 pm

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
Some functions need to interface with the current instance or with all instances.
The new instance system I was singing praises about for so long offers a simple interface to do this.

To fetch the currently active instance, use
Code: [Select]
enigma::instance_event_iterator.
Example:
Code: [Select]
int instance_destroy()
{
  enigma::instance_event_iterator->inst->unlink();
  return 0;
}

Iterating instances is about as easy.
As I've said, ENIGMA uses a unified iterator class. The class contains two members of concern; a pointer to the instance (guaranteeing only id and object_index members) and a pointer to the next iterator. If at any point the pointer is NULL, iteration is over.

An iterator can be fetched by an integer just like in EDL by using enigma::fetch_inst_iter_by_int(obj).

Example:
Code: [Select]
int instance_find(int obj, int num)
{
  int nth=0;
  for (enigma::inst_iter *it = enigma::fetch_inst_iter_by_int(obj); it != NULL; it = it->next)
  {
    nth++;
    if (nth>num)
    return (int) it->inst->id;
  }
  return noone;
}

A system has not yet been added to manipulate locals that are not guaranteed (such as health).
Variables that are key parts of the system (such as x and y) are included in different tiers of ENIGMA's instance system. The lowest tier is collisions, implementing bbox_* variables, and solid. The graphics tier implements such variables as sprite_index and image_index (which may eventually be removed as its use seems to indicate that placing it in system tiers is unnecessary). x,y, speed, direction, hspeed, and vspeed are implemented in the tier below that. Variables id and object_index are implemented in the bottommost tier.

Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #1 Posted on: September 09, 2010, 03:52:48 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
How to interface with rooms? I am trying to make sprite_tiled, but I need to know room_width/room_height, or even better would be view_width and view_height, as that would make sprites tile only in view, and thus eliminate call when outside the screen.
I tried including roomsystem.h and then just use room_width and room_height, but it trows:
Quote
../../Universal_System/roomsystem.h:46: error: `string' does not name a type
../../Universal_System/roomsystem.h:85: error: `string' does not name a type
../../Universal_System/roomsystem.h:86: error: `string' does not name a type
So I guess its not what I want to include? I saw that there are file like GMinstance.h and another file instance.h, which looks similar in function, so are some files redundant?
« Last Edit: September 09, 2010, 03:56:18 pm by HaRRiKiRi » Logged
Offline (Male) Josh @ Dreamland
Reply #2 Posted on: September 09, 2010, 04:05:39 pm

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
HaRRiKiRi: You should just be able to use them as-is. The resource is included after the rest of the variables.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #3 Posted on: September 10, 2010, 04:31:47 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Something like enigme:room_width? Because room_width isn't declared in the functions scope and it trows an error.

edit: Nevermind. extern int room_width, room_height; fixed it.

Also, I know that backgroundstruct.h exists, but there are no GSbackground.h and .cpp files, so can I try to create them so I can make some background functions? Or is it better for me to wait a little so you can make them in the distribution?
« Last Edit: September 10, 2010, 06:12:01 am by HaRRiKiRi » Logged
Offline (Male) Josh @ Dreamland
Reply #4 Posted on: September 10, 2010, 12:41:20 pm

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
If you feel you can, go for it. I forget where I left off with backgrounds; they may or may not be loaded properly. See backgroundinit.cpp.

Looks like I left off after checking how many backgrounds there are. I can finish that file later today.

If you are operating from "Stable," I suggest you unzip and run again, marking "Trunk" and "I'm a dev, don't touch my changes."

If you check out from the trunk, you'll be informed of an update every time I commit something new.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TGMG
Reply #5 Posted on: September 27, 2010, 01:05:36 pm

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
Whats the best way to get variables like sprite_index?
I was using this code which works in certain events, but causes a segfault in the create event :/ Is there a better way to do this?
((enigma::object_graphics*)enigma::instance_event_iterator->inst)->sprite_index=spritep;
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Unknown gender) TheExDeus
Reply #6 Posted on: September 27, 2010, 03:43:24 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
I see that TGMG added some basic background support. This will allow me to make all of the background functions. Thou I downloaded the newest from SVG, then recompiled, but I still don't see draw_background() function even thou its in GSbackground.cpp. I guess LGM needs to be updates as well? If so, then I will wait. :)
Logged
Offline (Unknown gender) TGMG
Reply #7 Posted on: September 27, 2010, 03:58:25 pm

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
@HaRRiKiRi - hey :) yeah i am in the process of adding them, i still have to commit the writing and reading code, test on windows and then you will see them in the lgm window. I'll update this post when i have everything sorted out.

Try now (remember to recompile the compiler, so delete the .dll file, lgm will compile it for you when the dll file is missing), atm its still quite basic.
« Last Edit: September 27, 2010, 04:24:50 pm by TGMG » Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Male) Josh @ Dreamland
Reply #8 Posted on: September 27, 2010, 08:04:12 pm

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
*slightly scared about new system he has no knowledge of*
TGMG: In the events of the object, sprite_index = spritep will suffice. If called from the create event, I understand the problem. I'll fix that ASAP.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #9 Posted on: September 28, 2010, 02:43:36 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Quote
Try now (remember to recompile the compiler, so delete the .dll file, lgm will compile it for you when the dll file is missing), atm its still quite basic.
Great work. :) I will make those functions when I get home.
Logged
Offline (Unknown gender) TGMG
Reply #10 Posted on: September 28, 2010, 04:16:00 am

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
*slightly scared about new system he has no knowledge of*
TGMG: In the events of the object, sprite_index = spritep will suffice. If called from the create event, I understand the problem. I'll fix that ASAP.
aye sorry about that, but its very similar to the way sprites are done.

well i was implementing the action functions and then realised that they always segfault in the create event, so I was using:
(enigma::object_graphics*)enigma::instance_event_iterator->inst)->sprite_index=spritep;
to access it
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Male) Josh @ Dreamland
Reply #11 Posted on: September 28, 2010, 12:00:45 pm

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
I see. Yeah, syntax checker doesn't like macros at the moment, but when I have that fixed, #define action_set_sprite(X) sprite_index = (X); is really the way to go.

Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TGMG
Reply #12 Posted on: September 29, 2010, 05:58:44 am

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
Ah thanks :)
Yeah I was going to implement them as functions then convert to macros when the parser can detect them but I just realised that this works:
Quote
void action_sprite_set(double spritep,double subimage, double speed);
#define action_sprite_set(spritep, subimage, speed) sprite_index=(spritep); image_index=(subimage);
So i can implement them that way for now :)

Although multi line macros don't work, when writing out the code to the event it includes the \ like so:
Quote
variant enigma::OBJ_obj_0::myevent_create()
{
  sprite_index =(spr_1);
  \ image_index =(0);
  ;
 
  return 0;
}
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Male) Josh @ Dreamland
Reply #13 Posted on: September 29, 2010, 07:03:47 am

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
Hm. Does that cause a compile error? It shouldn't. Either way, I'll take care of it.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: 1
  Print