Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 10:19 pm

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 420 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12 ... 28  Next
Author Message
 Post subject:
PostPosted: Mon May 30, 2011 1:47 pm 
Offline

Joined: Sun May 29, 2011 5:31 am
Posts: 6
Location: Texas
appel wrote:
I could also instead of having each system as it's own thread, have a pool of workers that equals to the number of cores on your machine, and have it consume jobs from a system pool. So, just good old Producer-Consumer pattern here, where processing a entity system is a job.


Doesn't slick already use two threads so adding another 4 threads leaving 2 that will be waiting to run at some point in time. Then again the wait would be minimal.

Can anyone confirm this for me?

_________________
My Github - https://github.com/warmwaffles


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 2:45 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
warmwaffles wrote:
appel wrote:
I could also instead of having each system as it's own thread, have a pool of workers that equals to the number of cores on your machine, and have it consume jobs from a system pool. So, just good old Producer-Consumer pattern here, where processing a entity system is a job.


Doesn't slick already use two threads so adding another 4 threads leaving 2 that will be waiting to run at some point in time. Then again the wait would be minimal.

Can anyone confirm this for me?


Honestly, I think going parallel is a waste of time for most games. You're better off optimizing for single-thread, and perhaps put special purpose stuff into a separate thread, like pathfinding.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2011 6:37 pm 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 64
Sorry if I misinformed people about what I am doing. I was using Artemis server side. Most of the game isn't made yet.

I had a interval system that needed to be executed no matter what at exactly the right interval without waiting for itself to finish. I removed the system since there are alternatives.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2011 12:41 pm 
Offline

Joined: Thu Jun 02, 2011 12:19 pm
Posts: 2
I've got a question on the best way to implement something.

I've got a Transform component which has variables for x, y and angle. I also have a Physics component which contains a Box2D body. The Box2D body also contains x, y and angle variables.

Each update in the PhysicsSystem, I update the Transform component with the position and rotation of the Box2D body from the Physics component. This works well because it means other systems (like rendering and camera following) can just use the Transform component and don't have to know about the Physics component. This also allows entities that don't have a physics body to have a position.

The problem I have now is how to easily set the position of an entity. I could change the data in the Transform component, but this would be overwritten in the next frame by the PhysicsSystem. I need a way to notify the Physics component when the data in the Transform component is modified.

The simplest way would be to just test if the entity has a Physics component when setting a position and update both. This seems easy, but it relies on the developer remembering to update the position for both.

I don't think putting a method to set the position in the Entity class is possible (or correct) and components shouldn't contain logic.

I could add a ChangePosition component temporarily to the entity and have a ChangePositionSystem that updates both the Transform and Physics components of the entity. This seems really hacky..

Is there a better way of doing this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2011 2:49 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
Dunno the best way, I can't share mine. I had almost the same problem you have, and the way I am handling it right now is by abstracting the Transform data outside the Component (I named it Spatial).

So, a Transform component has a Spatial (an interface, no component) with methods like setPosition(x,y), getX(), getY(), setAngle(alpha), more. I have one implementation of the Spatial that uses a Box2d body inside and set stuff accordingly.

With this abstraction, I can call set() or get() to the Spatial object in all places without knowing if the implementation is Box2d or other.

Also, imagine you want entities with no box2d stuff, you can create a Spatial implementation that uses x,y,alpha directly and all your systems and other classes will not know that, because you keep using the interface.

Here are some examples, in my case Transform is called SpatialComponent, then we have the Spatial and finally two implementations, with SpatialPhysicsImpl and SpatialImpl.

Hope it was clear and could be of help.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2011 6:13 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
It does not make sense to have such redundant information about position.

It's clear that you have two things in conflict with each other, Physics and Transform.

Question is, do you need Transform if you have Physics? Can't you just throw out Transform and just use Physics as it were Transform?

But then you might need to have a entity that is not part of the physics world?

Tricky. I don't have all answers really. This issue exists in other (entity/component) frameworks as well, so I can't really say it's related to the way Artemis is designed.

But my bet would be to somehow merge the two together. Perhaps just a Transform component, which can also have a Body (or not), and then a Transform system that detects if a Transform component has a Body or not to add it into a physics world.

I'm afraid there's really no clean solution if you wish to support both positional non-physics objects and positional physics objects.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2011 11:40 pm 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 64
I'd like to put in my input on a solution to Kazua's problem.

First of you can design your component however you want and it can have logic.

For example for each Physics component you have to check you could do a boolean check to see if that Physics component is enabled before you process it through your physics system.

Code:
//In your PhysicsSystem.process(Entity e)
Physics physics = physicsMapper.get(e);
if (physics.isEnabled()){
// Do physics logic here.
}


This way your logic is in one place and both maintainable and readable.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2011 9:43 pm 
Offline

Joined: Mon May 30, 2011 8:48 am
Posts: 3
appel wrote:
Sceptrix wrote:
Very nice framework!

I'm working on porting it to C++ right now. :D


Let me know how that goes, and I'll add it to the "ports" list.


I've mostly finished the framework, and am now working on the "starwarrior" game.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2011 1:42 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
Artemis C# port is feature complete. Starwarrior was ported too(using bare XNA 4). Check it out:

https://github.com/thelinuxlich/artemis_CSharp
https://github.com/thelinuxlich/starwarrior_CSharp

We are also working on a GUI for it:
http://www.ploobs.com.br/forum/viewtopi ... p=793#p793

I think this engine deserves its own forum or discussion group(Google?)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2011 2:04 am 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 64
thelinuxlich wrote:
Artemis C# port is feature complete. Starwarrior was ported too(using bare XNA 4). Check it out:

https://github.com/thelinuxlich/artemis_CSharp
https://github.com/thelinuxlich/starwarrior_CSharp

We are also working on a GUI for it:
http://www.ploobs.com.br/forum/viewtopi ... p=793#p793

I think this engine deserves its own forum or discussion group(Google?)

Method generics don't need to include a argument for type.

The code I saw is:
Code:
public override void ProcessEntities(Bag<Entity> entities) {
Entity e = EntityFactory.CreateEnemyShip(world);

e.GetComponent<Transform>(typeof(Transform)).SetLocation(r.Next(container.GetWidth()), r.Next(400)+50);
e.GetComponent<Velocity>(typeof(Velocity)).SetVelocity(0.05f);
e.GetComponent<Velocity>(typeof(Velocity)).SetAngle(r.Next() % 2 == 0 ? 0 : 180);

e.Refresh();
}

in your EnemySpawnSystem. e.GetComponent should not need to declare Velocity twice as the type. Even if it is a ComponentType.

If I am mistaken about what you are trying to do then I am sorry ahead of time.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2011 5:10 am 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
You are right, there were places where I forgot to change this stuff(I was converting StarWarrior together with Artemis), but this is old, I think you are reading a old revision


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2011 11:17 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Hey.

Fun.

I do wonder if you guys are taking advantage of the language features in C# or C++.

Been a while since I did some C# or C++ programming, but perhaps things can be done very differently, I don't know.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2011 12:56 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
I've been doing some microoptimizations and using Dictionary instead of Bag in some places. Other than that, I don't know if there are any more tricks on C# land :)

I fixed the Tag not being unregistered once its Entity is removed from the World, is it intentional to be unregistered manually?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2011 1:13 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
thelinuxlich wrote:
I fixed the Tag not being unregistered once its Entity is removed from the World, is it intentional to be unregistered manually?


Ah! I need to fix that :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2011 2:22 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
Why not removing entities from group(and also entitymanager) on World.deleteEntity(e)? Sometimes I have problems with a system deleting a entity and after that another system process a group that still has the deleted entity because world.loopStart() is not executed yet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 420 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12 ... 28  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group