Component-based Entities using Properties

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Trefall
Posts: 45
Joined: Tue Dec 05, 2006 8:49 pm

Post by Trefall »

Thank you Serengeor.
Edit: the sample code is outdated (I mean the main.cpp in SVN )
I'm afraid there is no samplecode available, only the examples given in the readme.

http://svn2.xp-dev.com/svn/Trefall-Comp ... tem/Source

The game I'm working on won't be released open source I'm afraid, but I'm working on a school project now who's using the component system as well.

http://svn.xp-dev.com/svn/NUCProjects/t ... aceOdyssey

Mind that this code is work in progress. It won't compile on your end less you put in some serious effort into making GMlib work with Qt Creator + work out my own little GMlib patches, but it should at least give some code examples on how the component system "can" be used.
Trefall
Posts: 45
Joined: Tue Dec 05, 2006 8:49 pm

Post by Trefall »

I've done a bit of updating to my source-code for the component system. Among other things I added an event system that sides with the commands system. I also added in the necessary source from ClanLib, so that the code will compile straight out from the box (at least for those running VC++).

I made some touch ups to the main.cpp example that was mentioned on the last page. Sorry, I had totally forgotten it was there! I added a seperate project for it, but it's included in the SLN file under /Source/. Make sure you download the component system from here:
http://svn2.xp-dev.com/svn/Trefall-ComponentSystem

The new component system is under the /Source/ folder. The ClanLib extraction is under /ClanLibExtract/, the event/command system I've included in it's own project as well, to extract it from the EntityEngine sourcecode /EventEngine/, and then there's the test application under /TestEntity/.

The test app is very simple. It includes three components. Health, Claws and Explosive. I then start it up with this piece of code:

Code: Select all

void main()
{	
	EntityEngine::ComponentFactory factory;
	ComponentRegistrator::Register(factory);

	//Make a barrel
	Object barrel(factory);
	barrel.setName("Barrel");
	barrel.setType("Barrel");
	barrel.setId(1);
	barrel.AddComponent("Health");
	barrel.AddComponent("Explosive");
	barrel.GetProperty<float>("Health") = 90.0f;
	barrel.GetProperty<float>("MaxHealth") = 100.0f;

	//Make a monster
	Object monster(factory);
	monster.setName("Monster");
	monster.setType("Monster");
	monster.setId(2);
	monster.AddComponent("Health");
	monster.AddComponent("Claws");
	monster.GetProperty<float>("Health") = 100.0f;
	monster.GetProperty<float>("MaxHealth") = 100.0f;

	monster.setTarget(&barrel);
	barrel.setTarget(&monster);

	//Inflict some damage to our barrel!
	monster.executeCommand(EventEngine::COMMAND_ATTACK_TARGET, NULL);

	monster.executeCommand(EventEngine::COMMAND_ATTACK_TARGET_SPECIAL, NULL);
}
Trefall
Posts: 45
Joined: Tue Dec 05, 2006 8:49 pm

Post by Trefall »

savuporo, over at Ogre3D forum, provided me with a patch a while back to extract the ClanLib dependency from the Entity Engine source code. I've now finally gotten around to implement it.

Check out Types_ClanLib.h for typedefs. Changing dependencies to a different library, like Boost, now only requires you to write a Types_Boost.h and include it in the precomp.h of EntityEngine, EventEngine and TestEntity.
Cyrano
Posts: 4
Joined: Wed Jul 28, 2010 6:50 pm

Post by Cyrano »

This system looks awesome! :)

Is there any way to download the whole package at once? Or do I have to copy and paste each and every file?
C'mon! Compile already!
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Cyrano wrote:This system looks awesome! :)

Is there any way to download the whole package at once? Or do I have to copy and paste each and every file?
You could try downloading tortoise SVN and read the manual how to use it ( it's really simple and very useful) :wink:
Working on game: Marrbles (Currently stopped).
Cyrano
Posts: 4
Joined: Wed Jul 28, 2010 6:50 pm

Post by Cyrano »

serengeor wrote:
Cyrano wrote:This system looks awesome! :)

Is there any way to download the whole package at once? Or do I have to copy and paste each and every file?
You could try downloading tortoise SVN and read the manual how to use it ( it's really simple and very useful) :wink:
I looked up TortoiseSVN and it seems that its main feature is version control and working with other SVN stuff. I don't need that. I would like something that allows me to grab all of the files in a CVS/Sourceforge style download. If it does this, it is not a primary feature on its features page.

If this kind of tool does not exist, I can always just do the laborious method...
C'mon! Compile already!
Cyrano
Posts: 4
Joined: Wed Jul 28, 2010 6:50 pm

Post by Cyrano »

Never mind. I go the code, and it IS awesome!
C'mon! Compile already!
Trefall
Posts: 45
Joined: Tue Dec 05, 2006 8:49 pm

Post by Trefall »

I'm glad to hear you like the entity system Cyrano :) And yes, the source code resides on a SVN repository, so TortoiseSVN is a good choice of client for downloading the code (I use that).

I'm still working and improving this system. Over the course of the summer vacation, I've added XML loading of objects + Lua scriptable components. I'll put this all into a new download bundle open source as soon as I get the time to do so, along with another one of these threads on how to use it.

If you have any questions, just add me to MSN, GTalk or AIM, and we'll discuss it's usage and approach :)
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Erm, and what's your email I would like to ask you some questions (over GTalk) if it's ok with you :)
Working on game: Marrbles (Currently stopped).
Trefall
Posts: 45
Joined: Tue Dec 05, 2006 8:49 pm

Post by Trefall »

PTrefall_ANTISPAM[AT]gmail[DOT]com

then take out the _ANTISPAM and you should be good to go :) I don't use that account for emails, only for GTalk btw.
Trefall
Posts: 45
Joined: Tue Dec 05, 2006 8:49 pm

Post by Trefall »

Just posted a journal entry in my GameDev.Net blog about how I integrated scripted components for my component system using Lua and LuaPlus C++ API.

http://www.gamedev.net/community/forums ... id=3742065
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Good work Trefall, I'll look into it when I'll get back from school :)
Working on game: Marrbles (Currently stopped).
dalerank2
Posts: 121
Joined: Thu Dec 03, 2009 7:41 am

more correct syntax

Post by dalerank2 »

I think that it is necessary to use more convenient syntax for properties, for example

Code: Select all

object["propName"] = anything; //for creating or changing
anything = object ["propName"]; //for getting
Trefall
Posts: 45
Joined: Tue Dec 05, 2006 8:49 pm

Post by Trefall »

How is that more convenient than:

Code: Select all

object:GetHP()
object:SetHP(hp)
object:GetOrientation()
object:SetOrientation(orientation)
etc?
dalerank2
Posts: 121
Joined: Thu Dec 03, 2009 7:41 am

Post by dalerank2 »

if you known in lua we can do MORE pretty syntax, forexample:
with overloading metamethods __index and __newindex

Code: Select all

object.hp = 100
hp = object.hp
object.orientation = { x=1, y=2, z=3 }
orient = object.orientation
is it more usability then function???
Post Reply