• entries
    503
  • comments
    1888
  • views
    333852

Instances

Sign in to follow this  

93 views

Instances, Instances, I love instances :)

We've covered a lot of ground, before the tangent about resources we had just finished talking about class objects. Class objects hold the immutable data that was designed in the Selenite Editor and provide information to instance objects, the data that actually changes during gameplay.

Types of Instances

Much like class objects, instance objects come in three different flavors, Game, Room and Actor; and much like before there are intermediate objects as their base classes StateObject and DisplayObject.


  • StateObject::Game

  • StateObject::DisplayObject::Room

  • StateObject::DisplayObject::Actor



A main difference between Class Objects and Instance Objects is that instance objects are designed to naturally form a tree, as Game->Rooms->Actors where Game is the root of the gamestate.

Allow me to use this great diagram to show the schema for each of the Instance Objects:


At first blush you might notice this diagram is less complicated than the class object diagram; this is a good thing.

Why less complexity in state is a Good Thing(TM)

When you save a game this data is what gets saved, as such it should be as light as possible, less data results in smaller save files but more importantly it means you are only saving what is necessary; since the game can change from patches but save games wont this is a good thing, it means less possible dependence on data saved in state (e.g. when I was saving resource file names in state).

An explanation of the instance objects

StateObject
The base class of all instance objects, StateObject holds information core to any element in the game.

  • id - the numerical id of this object, the selenite editor assigns unique sequential ids to objects at design time

  • logic - the logic counter value, this determines how often the 'logic' event is run for this object, where -1 is never, 0 is immediate and +0 is the number in seconds for the interval; commonly used in AI processing

  • sounds - a list of sounds that could be playing on this object, the list is related to Sounds in the StateClass object.



Game
The root of the gamestate, Game keeps global information as well as 'player' information.

  • selectedRoom - a pointer to the room the player is currently viewing

  • selectedActor - a pointer to an actor the player is currently controlling and which the camera is tracking

  • nextID - the next unique ID in line for creating new objects at runtime, initially baked in by the Selenite Editor, it gets incremented by new object creation at runtime and saved across states.

  • shake - a value that determines the amount of screen shake currently, fairly specific but an extremely common feature.

  • timeScaleAt - the current time scaling factor, used to speed up or slow down time, in addition to bend frequency for audio

  • timeScaleTo - where the time scale should eventually be, when doing a time scale shift

  • timeScaleVal - the value in 'value per second' that timeScaleAt approaches timeScaleTo

  • totalMilliseconds - a running counter of the number of milliseconds this game has been running for, used for statistics; a game state fresh out of the editor (game.bin) has a totalMilliseconds of 0

  • Items, a list of items, related to Items in GameClass, which keep the quantity of any items for the player; if an item quantity is 0 the player does not possess it, more than 1 and the player has multiples

  • Rooms - where the tree begins to branch, the Game object holds a list of Room objects which describe areas inside the game world.



DisplayObject
The common link between Rooms and Actors, a DisplayObject keeps information about colors, lighting and the concept that Rooms and Actors both have a Name

  • name - the display name of an object (e.g. "Princess Morning","The Ruins","Rusty Sword") this name is used for display in the game via mouse-overs and etc.

  • effect - the string name of the current HLSL effect this display object is using; rooms and actors can switch effects at will to change how the GPU renders them.

  • colorAt - the current color value (ARGB), color is used differently depending on rooms or actors; for rooms the color is a colored overlay; for actors it is a modulation of the actor's image data.

  • colorTo - where the color will end up for a color shift

  • colorVal - the rate (in values per second) that colorAt is moving to colorTo

  • lightAt - the current light value (RGB), light is used differently depending on rooms or actors; for rooms the light is the room light level and color; for actors it is the color of their emitted dynamic light, if they have one.

  • lightTo - where the light will end up for a light shift

  • lightVal - the rate (in values per second) that lightAt is moving to lightTo



Room
State-wise, room is rather un-interesting and mainly serves as the next branching of the state, Actors

  • visited - a boolean value, initially baked in as false and set to true when the player visits the room; useful for scripting purposes

  • Actors - within a room live actors, one of the more robust instance objects; Actors cannot live outside of a room, but may switch from room to room.



Actor
An extremely robust object, Actors are used for scenery, characters, audio and light emitters.

  • visible - if this actor is to be drawn

  • clickable - if this actor can be clicked on/rolled over etc.

  • shadow - if the engine should render a dynamic shadow for this actor

  • costume - the 'costume prefix' used to map a set of animations(walk,talk,etc.) to costume specific animations (battlewalk,battletalk,etc.)

  • direction - a numerical (from 0 to n, counter clockwise) value that determines direction, it's extent depends on the number of rows for an animation.

  • frame - the current 'frame' of an animation, as a column of the current animation table

  • animation - the name of the current animation (walk,talk,etc.)

  • mass - the physics body mass, where 0 is immovable

  • speed - the motion speed of an object measured in pixels per second when used with a move function.

  • linearDamping - linear, (translative) air resistance

  • angularDamping - angular, (rotary) air resistance

  • fixedRotation - if false the body can receive angular torques.

  • motionThreshold - value in meters at which to clamp velocity to 0

  • that was designed in the Selenite Editor and provide information to instance objects, the data that actually changes during gameplay.
  • brightnessAt - the current radius for an actor's light.

  • brightnessTo - where the radius will end up for a brightness shift

  • brightnessVal - the rate (in pixels per second) that brightnessAt is moving to brightnessTo

  • Topics - Related to Topics in ActorClass, they specify if certain topics are currently visible and which topics have been performed (chosen)



That pretty much wraps it up for state, with this data alone many great game scenario snapshots can be described; however without the proper business logic to change this data during gameplay it is effectively useless, and that is what we'll talk about next time... but until then I leave you with another diagram, a flattened view of a game sate tree, with one room and one actor in that room:

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now