Pages: [1] 2 3 ... 5
  Print  
Author Topic: Tierable Systems  (Read 7653 times)
Offline (Male) Josh @ Dreamland
Posted on: March 28, 2010, 10:16:04 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
Some people don't want a huge-ass graphics system or collisions system. Different systems can require more variables to operate than others. Switching out systems means incorporating different variables.

Solution:

Code: [Select]
struct parent_basic {
  const unsigned id;
  const int object_index;
  parent_basic(): id(0), object_index(noone) {}
  parent_basic(unsigned x, int y): id(x), object_index(y) {};
};

In the local directory of each graphics system:
Code: [Select]
struct inherit_graphics_GL : parent_basic  {
  int sprite_index;
  int image_index;
  inherit_graphics_GL() {}
  inherit_graphics_GL(int x, int y) parent_basic(x,y) {}
};

Of the collision system, which we assume to require graphics system:
Code: [Select]
struct inherit_collisions_colligma : inherit_graphics_GL   {
  int mask_index;
  inherit_collisions_colligma() {}
  inherit_collisions_colligma(int x, int y) inherit_graphics_GL(x,y) {}
};



Then finally, in the IDE Editable headers in which code is stored:

struct parent_locals :
Code: [Select]
#if USE_GRAPHICS
  #if USE_COLLIGMA
    #define high_tier inherit_collisions_colligma
  #else
    #define high_tier inherit_graphics_GL
  #endif
#else
  #define high_tier parent_basic
#endif

struct parent_locals: high_tier
{
  var health;
  var lives;
  var otherworthlessthings;
  //...
  parent_locals() {}
  parent_locals(unsigned my_id, int my_object_index): high_tier(my_id,my_object_index) {}
};


This is being implemented for testing *now.*

Note: I left out X and Y for brevity. They will be assumed to be needed before collisions but after graphics.
« Last Edit: March 29, 2010, 08:14:00 AM by Josh @ Dreamland » 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 (Male) Rusky
Reply #1 Posted on: March 29, 2010, 09:07:45 AM

Resident Troll
Joined: Feb 2008
Posts: 960
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
How about multiple inheritance or a component system so you could combine them in more ways? Collisions, graphics, both or neither?
Logged
Offline (Male) Josh @ Dreamland
Reply #2 Posted on: March 29, 2010, 09:44:29 AM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
I considered it (it was in fact my first thought), but then indexes could end up different between files, and thus a file could end up reading the wrong block of memory to fetch its variable.

Like using int vs a variant type for x and y: changing the size based on multiple inheritance could totally fuck up collision code, as it would suddenly be reading 12 bytes further than where it should be for each variant that became an int.

The solution would be to include the settings file to understand which size it was looking at, but doing so would require recompile, and that is exactly what this tier system is designed to avoid.

Edit: let me clarify.
Each new step in the tier must assume as few sizes as possible from the previous ones. We want systems to be removable or swappable, but allowing a system to be changed can likely impact the behavior of other parts of the system. In this hierarchy, the affected parts will all be lower tiers. For instance, if you removed graphics, the assumption is that you'd have no further need for collisions.

The instance functions can make use of tier one, needing only ID and object index. They'll never even notice if the collision system is removed or changed.

There is still some need for recompile, but with completely linear tiers it becomes seldom or trivial enough to where a new source file can be made to accommodate each change to a lower tier. Multiple inheritance could vastly screw that up.
« Last Edit: March 29, 2010, 09:59:40 AM by Josh @ Dreamland » 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) luiscubal
Reply #3 Posted on: March 29, 2010, 12:41:12 PM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
What about invisible walls?
Logged
Offline (Male) Rusky
Reply #4 Posted on: March 29, 2010, 12:52:31 PM

Resident Troll
Joined: Feb 2008
Posts: 960
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
Virtual accessor functions?
Logged
Offline (Male) Josh @ Dreamland
Reply #5 Posted on: March 29, 2010, 01:07:19 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
> Virtual accessor functions?
Could work, then I'd have to hope they were always inlined. I'll look into it if I need. They won't help much since they'll need to be given a certain type as well, but they could allow for multiple inheritance. I'll see if they come in handy.

> What about invisible walls?
Not sure what you're referring to.
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 (Male) Rusky
Reply #6 Posted on: March 29, 2010, 01:28:34 PM

Resident Troll
Joined: Feb 2008
Posts: 960
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
Virtual and inline are mutually exclusive.
Logged
Offline (Male) Josh @ Dreamland
Reply #7 Posted on: March 29, 2010, 01:33:17 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
Well, that settles that, then.
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) luiscubal
Reply #8 Posted on: March 29, 2010, 01:36:29 PM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
Quote
> What about invisible walls?
Not sure what you're referring to.
Anything invisible that affects the collision system.
Logged
Offline (Male) retep998
Reply #9 Posted on: March 29, 2010, 01:38:47 PM

Member
Location: Where else?
Joined: Jan 2010
Posts: 248
MSN Messenger - retep998@charter.net AOL Instant Messenger - retep998 Yahoo Instant Messenger - retep998
View Profile Email
Code: [Select]
//Objects
#ifndef _OBJECTS_
#define _OBJECTS_

#ifndef _OBJECT_INDEX
#define _OBJECT_INDEX
var object_index;
#endif

#ifndef _OBJECT_ID
#define _OBJECT_ID
var id;
#endif

#endif
Code: [Select]
//Collisions
#ifdef _OBJECTS_
#ifndef _OBJECT_COLLISIONS_
#define _OBJECT_COLLISIONS_

#ifndef _OBJECT_X
#define _OBJECT_X
var x;
#endif

#endif
#endif
Code: [Select]
//Drawing
#ifdef _OBJECTS_
#ifndef _OBJECT_DRAWING_
#define _OBJECT_DRAWING_

#ifndef _OBJECT_X
#define _OBJECT_X
var x;
#endif

#ifndef _OBJECT_SPRITE
#define _OBJECT_SPRITE
var sprite_index;
#endif

#endif
#endif
Such a system would have a lot of preprocessor calls, however it would work fairly well (unless Josh got something better) and would be able to handle invisible walls like luiscubal said.
« Last Edit: March 29, 2010, 01:43:25 PM by retep998 » Logged
Offline (Male) Josh @ Dreamland
Reply #10 Posted on: March 29, 2010, 01:41:28 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
> Anything invisible that affects the collision system.
"visible" is part of the graphics tier.

retep:
extern is a great keyword
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 (Male) retep998
Reply #11 Posted on: March 29, 2010, 01:45:08 PM

Member
Location: Where else?
Joined: Jan 2010
Posts: 248
MSN Messenger - retep998@charter.net AOL Instant Messenger - retep998 Yahoo Instant Messenger - retep998
View Profile Email
retep:
extern is a great keyword
What would extern do to make it better?
Logged
Offline (Male) Rusky
Reply #12 Posted on: March 29, 2010, 01:51:53 PM

Resident Troll
Joined: Feb 2008
Posts: 960
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
retep, what on earth does that do? Josh, why would you limit the ways you can remove stuff? That seems rather counter-intuitive. What if you wanted to make an invisible wall by entirely removing the graphics system?

It would make even more sense to give objects GrahpicsComponents, CollisionComponents and OtherSystemCompoents. It would make different system changeable at runtime (e.g. for instance_change or game options), definable by DLL's, distributed as extremely reusable "behaviors", etc. If you designed a good interface between them you would need less explicit member access, and all the functions that are doing more general things (built-in systems, for example) wouldn't have any speed problems.
Logged
Offline (Male) Josh @ Dreamland
Reply #13 Posted on: March 29, 2010, 01:52:14 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
Remove all those #ifdef #define pairs I can't find another explanation for. If they were so other systems could check if the variable has been implemented, that goes against the purpose of tiering (we'd have to go back over everything and recompile).

Rusky--
And every third instruction would be CALL. Not happening.
Furthermore, "wouldn't have any speed problems..." Do you have ANY research to back this up? Hello, you want me to throw in a function call every time I want object.x? When object is already a pointer? What the FUCK? I'm to the point where I'm unhappy about busing a DWORD back and forth from the RAM, and you want me to make a CALL for it instead. We're talking 6x the number of clocks, easily. That statement genuinely pissed me off this time.

If you want a text-based game with a collision system operating in a terminal window, I'm not programming for you.
Same for if you want to change your fucking mind about what operating system the game is for at runtime. Jesus.
« Last Edit: March 29, 2010, 02:07:57 PM by Josh @ Dreamland » 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) Micah
Reply #14 Posted on: March 29, 2010, 05:24:28 PM

Resident Troll
Joined: May 2008
Posts: 129

View Profile
wow
Logged
Pages: [1] 2 3 ... 5
  Print