Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Kristoffer

Member Since 07 May 2005
Offline Last Active Sep 23 2014 10:10 AM

#5121256 Entity component system: efficient component retrieval?

Posted by Kristoffer on 04 January 2014 - 06:08 PM

Does your PositionBehavior have a list of all Positions components? if so then it can update them without getting them from the object itself.

 

This is how I do my component updates.




#5051792 C++ Entity/Component System Setup Assistance

Posted by Kristoffer on 10 April 2013 - 05:51 AM

Hey taurusrow 

 

I have been experimenting with component based object system now for a couple of years and the results have been getting better and better each time, currently I am actually streaming my current programming project live on http://www.twitch.tv/devmoon

 

I am using a very decoupled component/subsystem approach where each subsystem is completely independent and currently I have these systems but it will be more later

  • Transform
  • Physics
  • Collision
  • Timer
  • Editable
  • Render

To answer your questions

 

An object consists of the following

  • Unique ID
  • Object name (a pointer to a template that keep tracks of the name it was instanced with)
  • Array or component pointers
  • Internal messaging system (being able to communicate with the components)

A component consists of

  • Pointer to the object its attached to (so it can communicate)
  • Custom data its working on (position in the transform component etc..)
  • Pointer to the subsystem

A subsystem consists of

  • A vector of components (that is pre allocated)
  • Updates the components that have been used by any object

 

From my experience component based object systems is not some kind of "solve all your problems" but just another way to manage your game objects. You still need to craft it to fit your needs.

 

To update everything I have an ordered list of all my subsystems and call their update method

 

Here is also a script example of how it can be used (lua script)

 

sample_object =
{
	on_created = function(self)
	
		self:add_component("Transform")
		self:add_component("Physics")
		self:add_component("Collision", {width = 10, height = 10})
		
		self:add_component("Render")
		
		self:add_component("Editable")
		self:add_component("Timer", {[70] = instance_destroy})
	end,
	
	on_collision_enter = function(self, other)
	
		if (other.solid) then
			instance_destroy(self)
		end
	end,
	
        -- if there is no render method there is no overhead of trying to call one
	on_render = function(self, x, y, z)

                -- some custom draw code here if needed
	end
}

 

 

I do stream programming almost every day and you can ask me anything and I might make all the code available for public at a later date

 

Good luck with the component systems it is really fun to work with smile.png




#4961652 How commercial games do the packing?

Posted by Kristoffer on 21 July 2012 - 07:13 AM

By using libs like (for example PhysicsFS) you can search and load the assets in the package as if they were in the filesystem, combine it with functions like
CreateTextureFromMemory and you can just pass a pointer to a chunk of uncompressed memory for the texture that has been loaded from the package.

There is many other similar working libs but i guess the inner workings is the same but some might use a more secure format other than ZIP.


#4909170 lua multiple return values

Posted by Kristoffer on 03 February 2012 - 08:31 AM

Yes,

leave the arguments that you want to return on the stack and let the C function return the numbers of arguments you want to return to lua

// psudeo
int cfunction(lua_State * state)
{
	 push(arg1)
	 push(arg2)

	 return 2;
}



PARTNERS