LGP Objects
From NexusCrossing
Contents |
[edit] Introduction
All game worlds have things in them. These things include people, creatures, objects, etc. I intend for libGamePieces to be able to support objects in a flexible and logical way. One important thing from a programmer's and later a world developer's standpoint is the ability to create and track objects. This will be achieved through the use of the World Object. class lgp::World includes an element named ObjectListM. Coupled with the method getObjectById(), the programmer will be able to access objects, and manipulate them in various ways. It's main purpose is to be able to let the programmer locate the object they are using and retrieve the basic information needed to access that object.
In practice, when an object is created it is added to the object list. When an object is destroyed, it is removed from the object list. Each instance of lgp::World will maintain a count of existing objects, as well as the highest Object ID that has been assigned to an object that it contains.
[edit] lgp::Object
lgp::Object is the default base object class. Unlike the original version of the lgp::Object that was invisioned, the current iteration is a true abstract class that cannot instantiate Objects of its own.
The current interface is as follows:
class Object
{
public:
Object();
virtual ~Object();
virtual ObjectID id(void);
virtual ObjectData type(void);
virtual void accept_message(std::string message);
virtual void cycle(void)=0;
};
[edit] The Interface
First it is important to notice that everything except the constructor is virtual. This is because everything except the constructor should be implemented at the individual class level. To be honest, I cheated and added in some very basic default behavior for everything except for cycle(). cycle() is important, because this is what will control a lot of the behavior for various objects. cycle() is like the control loop fora given object.
id() and type() return the objects Object ID or Object Type respectively. I may chage this to get_id() and get_type() later, depending on what people thing is prefferable.
accept_message() is used to pass a message to the object. This will most often be called by container that is holding the object.
cycle() is the member function that is called every "cycle" in the game to tell objects to process whatever they need to do in a cycle, turn, whatever you want to call it. At a minimum this should involve processessing any messages in the objects MessageQueue.
[edit] lgp::World
lgp::World is derived directly from lgp::Object.
lgp::World provides the functionality required to create and track objects within the game world. It is a container class and Object factory. It will contain member functions to create, access, modify, and destroy other objects.
Instances of lgp::World will see themselves as object 0 (#0).
When lgp::World is created, it will point to itself as #0, and it will create another object #-1 (NullObject) which is not actually in its list. This will be the generic "It's just not there," object.
For identifying Objects by Object ID number in contexts outside of the most basic functions, I will often reffer to an object number with the format #NNN (Where NNN represents the object's ID number). This is a holdover from how objects are identified in MooCode. MooCode is very inspirational.
[edit] Notice:
At the current time, lgp::World has not been implemented in the current iteration of LGP, but it is still envisioned as a part of the system. Everything bellow this point on the page is still heavily up in the air, but is still good to contemplate when thinking about the theory of how things operate within the system.
[edit] lgp::Thing
lgp::Thing is the base Object class for every sort of object that is seen to "exist" within the game world. This will include everything from rocks to swords to canaries. Everything that is "made of something" is derived from lgp::Thing.
[edit] lgp::Creature
lgp::Creature is the base class for creatures. It is derived from lgp::Thing.
[edit] A Graphical Representation
- Note that lgp::Item does not exist yet (as of the time this image was uploaded), but serves as an example.
[edit] LGP Project Components (TOC)
- LGP Top Page
- The Project Road Map
- Project News
- LGP Classes and Components
- LibGamePieces Objects <== Stand By for Heavy Rolls
- The Virtual Dicebag
- Project Dependencies (Outside Code you need to get it to compile)
- The Game System <== May be in Flux
- World Design

