Update 3-1-2008
Cobblestones is moving along rather well now. The base object class is done, as is the level class. I integrated Irrnewt into it all, so there is now a physics side to things.
CSApp - container for the application
CSEngine - easily create the Irrlicht 'stuff'. Wrapper for gui, driver, device etc...
CSObject - base object class with little data or code. All game objects
derived from it.
CSLevel - container for the object factory. the object factory is pretty cool if I do say so myself. explanation following.
The factory scans the 'objects' directory and creates a list of available objects. These objects are in their own DLL files and the factory looks for a specific function residing in the DLL file. It then builds a list of DLL's and the object classes available in each one (there can be multiple object classes in a single dll file) The objects can then be created by calling the CreateObject(char* objecttype) function in the DLL, added to the factory, and then used in the game. What this allows me to do is create a single application that never needs recompiled. The application simply scans for objects, loads then according to a script and then the objects are completely aware of the world and other objects, but the world is not aware of them. A little hard to explain, but exciting for me none the less.
an example file
Code: Select all
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the CSOBJECT_ITEM_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// CSOBJECT_ITEM_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef CSOBJECT_ITEM_EXPORTS
#define CSOBJECT_ITEM_API __declspec(dllexport)
#else
#define CSOBJECT_ITEM_API __declspec(dllimport)
#endif
#include "CSApp.h"
// This class is exported from the CSObject_Item.dll
class CSOBJECT_ITEM_API CSObject_Item : public CSObject
{
public:
// class contrcutor / destructor
CSObject_Item::CSObject_Item() { Initialize(); }
virtual CSObject_Item::~CSObject_Item() { Cleanup(); }
// set all variables to a knwon value
virtual void Initialize()
{
// begin the state machine
CSStateMachine::Initialize();
}
// dual creation allows for better error handling
virtual bool Create(CSLevel* level)
{
// create the base class, this assigns an ID to the CSObject
CSObject::Create(level);
SetName("CSObject_Ball");
// grab a few useful pointers
video::IVideoDriver* driver = level->m_App->m_Engine->m_Driver;
scene::ISceneManager* smgr = level->m_Smgr;
scene::ICameraSceneNode* camera = level->m_Camera;
// add a simple sphere
m_Node = smgr->addSphereSceneNode(25);
m_Node->setMaterialFlag(video::EMF_LIGHTING,false);
m_Node->setMaterialTexture(0,driver->getTexture("media/water.jpg"));
m_Node->setID(GetId());
// create the newton body
m_Newton_Body = level->m_NewtonWorld->createCharacterController(
level->m_NewtonWorld->createBody(m_Node));
m_Newton_Body->setUserData((void*)this);
m_Newton_Body->setMaterial(level->Newton_Material_Fireball);
SetGravity(true);
return true;
}
virtual bool Cleanup()
{
Initialize();
return false;
}
virtual void Frame()
{
CSObject::Frame();
}
virtual void Collision()
{
SetState(STATE_COLLISION);
}
virtual bool ProcessStateMachine(CSObjectMessage* msg)
{
BeginStateMachine
// when Entering the state machine, default to idle
OnEnter
SetState(STATE_CREATE)
State(STATE_CREATE)
// nothing special
State(STATE_IDLE)
OnEnter
// set the objects velocity to 0
if (m_Newton_Body)
{
m_Newton_Body->setTorque(vector3df(0,0,0));
m_Newton_Body->setVelocity(vector3df(0,0,0));
}
State(STATE_COLLISION)
OnEnter
State(STATE_DYING)
OnEnter
m_Timer = 0;
OnUpdate
m_Timer++;
SetState(STATE_DEAD);
State(STATE_DEAD)
OnEnter
SetDead(true);
EndStateMachine
}
};
extern "C"
{
CSOBJECT_ITEM_API bool QueryIsCSObject();
CSOBJECT_ITEM_API bool QueryIsObjectType(char* objecttype);
CSOBJECT_ITEM_API void* CreateObject(char* objecttype);
CSOBJECT_ITEM_API char* QueryAllObjectTypes();
CSOBJECT_ITEM_API char* QueryObjectDescription(char* objecttype);
};
Code: Select all
// CSObject_Item.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "CSObject_Item.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
/////////////////////////////////////////////////////////////////////
// these functions MUST be implemented in every game object class
// so that the CSObjectFactory can locate and create the objects
/////////////////////////////////////////////////////////////////////
// simple test to determine if dll holds a CSObject class
bool QueryIsCSObject()
{
return true;
}
// define this for ease of reading
#define OBJECTTYPE "CSObject_Item"
// tell all of the object classes that reside in this dll.
#define ALLOBJECTTYPES "|CSObject_Item|"
// simple function to determine the type of CSObject this dll holds
bool QueryIsObjectType(char* objecttype)
{
return (!stricmp(objecttype,OBJECTTYPE));
}
// simple fucntion to determine the type of CSObject this dll holds
char* QueryAllObjectTypes()
{
return ALLOBJECTTYPES;
}
// create a reference of the object type
void* CreateObject(char* objecttype)
{
if (!stricmp(objecttype,"CSObject_Item"))
{
// temporary variable
CSObject_Item* object = NULL;
// attempt to instantiate the object
object = new CSObject_Item();
// if we succedded
if (object)
{
// return the object we creaed in case someone wants the pointer.
return object;
}
}
// something went wrong
return NULL;
}
// simple function to access a description of the objects in this dll
char* QueryObjectDescription(char* objecttype)
{
if (!stricmp(objecttype,"CSObject_Item"))
{
return "This object is intended to be used as a test pattern\n\
It really serves no purpose except to test the application\n\
The excitement comes from the fact that the\n\
application knows nothing of the object.";
}
return "UNKNOWN";
}
/////////////////////////////////////////////////////////////////////
// end - these functions MUST be implemented in every class
/////////////////////////////////////////////////////////////////////
to use this object, I can simply do this........
Code: Select all
int id = CreateObjectByType("CSObject_Item");
CSObject* b = m_Factory->GetObjectPointer(id);
if (b)
{
b->SetPosition(m_Camera->getPosition());
b->SetRotation(m_Camera->getRotation());
b->AddForwardForce(500);
}
anyhow, enough rambling. If you would like to check it out, feel free to download the demo. It isnt the most stable program in the world, so if you try to break it, I am sure that you will succeed.
http://zedit.wiki.sourceforge.net/space ... esDemo.ace
commands
Code: Select all
ESCAPE always brings you to the top level menu class
Editor - a simple test bed for the editor object.
.... right click toggle mouselook vs selecting
.... tab1 a list of currently created objects - mo interaction
.... tab2 a list of available classes to create
........... feel free to create
.... left click and hold to select object.
........ move left clicked mouse to move object
............. hold shift key to affect 'Y' coordinates of object
Newton Test - looks empty, but is the most powerful
..... right click toggle mouselooks vs selection
..... tab key toggles editor mode (no camera move while in editor mode)
.........same as editor above
if not editor mode, then left click creates ball that interacts with world.
Slideshow - a simple test of the menu system
...... scrollbar determines slideshow speed
Meshviewer - another test of the menu system. nothing special in here yet.