Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Wolftein

Member Since 13 Jun 2011
Offline Last Active Aug 05 2015 05:28 PM

Topics I've Started

Component based system

26 September 2013 - 05:14 PM

Hello, so i'm designing a entity component based system for my engine (Based of Artemis design).

Most of the example code i watched, has static containers and static stuff. My question is, is that a good idea?, my design is an hybrid approach of both dynamic and static implementation since i can add and remove system from my plugins dynamic.

My current design is:

Component
  -> isActive(), setActive(bool) [this is when the entity owner is sleeping]
  -> isValid(), setInvalid()         [When the entity owner removes the component or the entity is destroyed]
  -> getId()                              [ID of the component class]

Componentable<T> : Component
  -> static ID                            [This is for mapping]
  -> Component::m_Id = typeid(T).hash_code() [Get ID of the class at compile time]

ComponentCollection<T>
  -> addComponent, getComponents, disposeComponent [Store contiguous each component of the same type] for CPU cache.

ComponentManager (Map ComponentID To ComponentCollection)
  -> addCollection<T>           [Add a collection of components into a map]
  -> getCollection<T>            [Get a collection of components from a map]

ComponentHolder
  -> addComponent<T>, getComponent<T>, hasComponent<T>, invalid(), removeComponent<T>

  -> Holders contain a pointer to the components owned.
 

System<T>

  -> Logic part of the component
  -> Iterate over each component of the same type, those components invalidated will be removed from the collection, and those sleeping
      will not be executed.

SystemManager
  -> Contains every system registered

World
  -> Contains a system manager and creates an entity (Component holder + ID)


How it works?
 

struct LifeManaComponent : Componentable<LifeManaComponent>
{
    uint32_t m_Life, m_Mana;
};   

struct DefenseComponent : Componentable<DefenseComponent>
{
   uint32_t m_Defense, m_Attack, m_RecvDamage;
}

class AttackSystem : public System<LifeManaComponent, DefenseComponent>
{
    void OnExecute(Entity & entity)
    {
           ....
    }
};
//////////////////////////////////////////////// Code /////////////////////////////////////////////////////////////////
    World->AddComponentCollection<LifeManaComponent>();
    World->AddComponentCollection<DefenseComponent>();
    World->AddSystem<AttackSystem>();

    auto & pHolder = World->CreateEntity();
    pHolder.addComponent<LifeManaComponent>(30 /* Life */, 0 /* Mana */);
    pHolder.addComponent<DefenseComponent>(0, 0, 0); // Now the entity will be eligable for attackSystem.
    pHolder.hasComponent<LifeManaComponent>(); // Return true
    pHolder.getComponent<LifeManaComponent>(); // Return attack component reference.
    pHolder.invalidate(); // Invalid all components
        

    World->RemoveSystem<AttackSystem();
    World->RemoveComponentCollection<DefenseComponent>();

UPDATE: CODE


A retro journey.

25 September 2013 - 07:20 AM

Hello, my name is Agustin and i'm a 23 year old programmer who likes video games. My first video game was at the age of 5, and if I remember correctly was Master of Magic; a fantasy turn based strategy that I love. I found my call at the age of 11 when I coded my first line of code for an open source mmorpg game, using Visual Basic. Since that day I had been coding and learning a lot about video games and how to make them.

So I decided to start my own personal journey and do what I like the most, code from ground all those games that I loved for all these years, not just for me, but for all those people that feel the same. My vision is to extend them all, using technology that wasn't at that time, that would make them a piece of art.

 

To be able to extend them, i'm currently coding a C++ modding platform, that will allow to mod each one of them, not just for me, but for all those people that wants to add their own assets to the games. The engine is called Ghrum and that is why i'm here today. The engine can be found Here.

 

Planned Games:

  1. Dune 2
  2. Master of Magic
  3. X-Com Apocalypse
  4. ... More games to come.

 

If you love those games like I do, please leave a message and if you want to help me in my journey, please write me to wolftein1@gmail.com. Thank you for taking the time to read this.


A Resource manager design.

12 September 2013 - 12:35 PM

Hello!, i'm trying to design my own resource/asset manager for my own game engine. I would like feedbacks or any opinion on how may i improve it. The design is:

IResourceLocator: A class that represent a place where to look for the files.
Examples: FileLocator, ZipLocator, UrlLocator.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceLocator.hpp
Example Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/Locator/File/FileResourceLocator.hpp

IResourceLoader: A class that define how an resource is loaded.
Examples: ImageLoader, AudioMP3Loader, AudioOGGLoader.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceLoader.hpp

IResourceCache: A class that define how is the resource stored.
Example: WeakReferenceCache, ContignousMemoryCache.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceCache.hpp

And finally the resource manager that keeps track of every IResourceLocator, IResourceLoader and IResourceCache. Each module is comunicated using a ResourceKey that contain the name and file of the resource.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceManager.hpp

An example of usage:

void onInitialization(IResourceManager & manager)
{
    manager.registerLocator<FileLocator>("." + PATH_SEPARATOR + "cache");
    manager.registerLocator<ZipLocator>("." + PATH_SEPARATOR + "data" + PATH_SEPARATOR + "textures.zip");
    manager.registerLoader<ImageLocator>("png", "jpg", "jpeg");
}


void onSomethingElse(IResourceManager & manager)
{
   auto & resource = manager.getResource<Image>("texture.png");
}

Any feedback or tip will be appreciated.


[HELP]: Render at center of the screen.

20 June 2011 - 11:16 PM

Hi, i'm trying to render at the center of the screen, being 0,0 at the top-left. What i'm doing wrong here?


	public World(int numRow, int numCol) {
    	this.tiles = new Tile[numRow][numCol];
    	this.centerViewRow = numRow * 0.5f;
    	this.centerViewCol = numCol * 0.5f;
	}

	protected void setViewport(float width, float height) {
    	this.viewport.x = width;
    	this.viewport.y = height;
    	// Set the new viewport of the world
    	this.modelViewRow = (viewport.y / WorldManager.TILE_HEIGHT);
    	this.modelViewCol = (viewport.x / WorldManager.TILE_WIDTH);
	}

	private void calculateWorldBounds() {
    	// Find the tiles we should render. We are doing pre cull phase here,
    	// we're not going to render all the map because it will be ineficient.
    	tileMinRow = (int) Math.max(0, centerViewRow - modelViewRow);
    	tileMaxRow = (int) Math.min(centerViewRow + modelViewRow, tiles.length);

    	tileMinCol = (int) Math.max(0, centerViewCol - modelViewCol);
    	tileMaxCol = (int) Math.min(centerViewCol + modelViewCol, tiles[0].length);

    	// Calculate from where the screen we are going to start drawing. This
    	// is because we have a centered view over a point
    	renderRowPos = (viewport.y * 0.5f) + WorldManager.TILE_HEIGHT;
    	renderRowPos += ((centerViewRow - tileMinRow) * WorldManager.TILE_HEIGHT);
    	renderColPos = (viewport.x * 0.5f);
    	renderColPos -= ((centerViewCol - tileMinCol) * WorldManager.TILE_HALF_WIDTH);

    	maxBoundaryY = renderRowPos + WorldManager.TILE_HALF_HEIGHT;
    	minBoundaryY = renderRowPos - (tileMaxRow - tileMinRow) * WorldManager.TILE_HEIGHT
            	- WorldManager.TILE_HALF_HEIGHT;

    	minBoundaryX = renderColPos - (tileMaxCol - tileMinCol) * WorldManager.TILE_HALF_WIDTH;
    	maxBoundaryX = renderColPos + (tileMaxCol - tileMinCol) * WorldManager.TILE_HALF_WIDTH;
	}

	private void renderWorldTiles(Renderer2D renderer, float deltaTime) {
    	// Current rendering variables
    	float currentScreenRow = renderRowPos;
    	float currentScreenCol = renderColPos;

    	// Loop though all the rows (X)
    	for (int x = tileMinRow; x < tileMaxRow; x++) {
        	// Make the absolute diamond shape coordinates
        	currentScreenRow = (renderRowPos - (x - tileMinRow) * WorldManager.TILE_HALF_HEIGHT);
        	currentScreenCol = (renderColPos - (x - tileMinRow) * WorldManager.TILE_HALF_WIDTH);
        	// Loop though all the columns (Y)
        	for (int y = tileMinCol; y < tileMaxCol; y++) {
            	// Render the tile if it's valid.
            	if (tiles[x][y] != null) {
                	tiles[x][y].render(renderer,
                        	deltaTime,
                        	currentScreenCol + scrollCol,
                        	currentScreenRow + scrollRow);
            	}
            	// Make the diamond shape
            	currentScreenCol += WorldManager.TILE_HALF_WIDTH;
            	currentScreenRow -= WorldManager.TILE_HALF_HEIGHT;
        	}
    	}
	}

Posted Image

Help with 3D isometric

13 June 2011 - 09:54 AM

Hi, first of all sorry about my bad english, it's not my first language xD.

I'm having trouble to create my 3D isometric engine. I'm trying to create 3D boxes in a 2D isometric world, but i don't know how to do it :(.

1) What should i do? Render the scene in perspective or ortho mode?(Ortho mode with -width, width, -height, height, -far, far).
2) What is the order of matrix multiplicacion for rendering an object? (For example Projection * View * Model?), i'm doing that and i'm getting weird results.
3) How can i render a 3D box in a 2.5D o 2D world?
4) In perspective mode, how can i render all at a relative location. (For example i want to render a box at 0,0 world with 32 width, 32 height, 32 depth (Isometric tiles size))
5) How can i scale, and position an object in perspecitve like in ortho mode. I mean if i scale an object 32px in ortho, how much will be in pespective mode?

6) What is that i'm doing wrong this is my pipeline
1) Set the camera to perspective with 70.0f field of view
2) Set the position of the camera at 3.0, 3.0, 3.0   ]__ This will allow to see any 3D objects in isometric view
3) Set the look of the camera to 0.0, 0.0, 0.0      	]
4) Create a box with all his vertexs 1.0f, at the location 10, 10 (Tile location)
5) The world will render all the objects and calculate the position of the box, let say the worlds need to render the box at 200,100 (Screen cordinates), it will unproject the location of the screen, and update the matrix by translating and scaling in the same way unprojecting the scale size.
6) Then it render into the screen using GLSL.

1, 2, 3)
    	this.theCamera = new Camera3D(70.0f, width, height);
    	this.theCamera.position.set(3.0f, 3.0f, 3.0f);
    	this.theCamera.lookAt(0.0f, 0.0f, 0.0f);
4)
    	float[] geometryVertex = new float[]{
        	-1.0f, -1.0f, -1.0f,
        	-1.0f, -1.0f, 1.0f,
        	1.0f, -1.0f, 1.0f,
        	1.0f, -1.0f, -1.0f,
        	-1.0f, 1.0f, -1.0f,
        	-1.0f, 1.0f, 1.0f,
        	1.0f, 1.0f, 1.0f,
        	1.0f, 1.0f, -1.0f,
        	-1.0f, -1.0f, -1.0f,
        	-1.0f, 1.0f, -1.0f,
        	1.0f, 1.0f, -1.0f,
        	1.0f, -1.0f, -1.0f,
        	-1.0f, -1.0f, 1.0f,
        	-1.0f, 1.0f, 1.0f,
        	1.0f, 1.0f, 1.0f,
        	1.0f, -1.0f, 1.0f,
        	-1.0f, -1.0f, -1.0f,
        	-1.0f, -1.0f, 1.0f,
        	-1.0f, 1.0f, 1.0f,
        	-1.0f, 1.0f, -1.0f,
        	1.0f, -1.0f, -1.0f,
        	1.0f, -1.0f, 1.0f,
        	1.0f, 1.0f, 1.0f,
        	1.0f, 1.0f, -1.0f};

5)
        	for (int y = tileMinY; y < tileMaxY; y++) {
            	for (int x = tileMinX; x < tileMaxX; x++) {
                	// Does we need to render the grid? it's available?
                	// there is 
                	if (grids[x][y][z] != null && grids[x][y][z].theActor != null) { 	
                    	// Render the tile and
                    	grids[x][y][z].render(renderer,
                            	deltaTime,
                            	curRenderX + scroll.x,
                            	curRenderY + scroll.y,
                            	1.0f);

 public void render(Graphics3D renderer, float deltaTime, float x, float y, float z) {
    	// Calculate the screen position into world position
    	Vector3D worldPoint = new Vector3D(x,
            	y,
            	0.0f);
    	IsoSceneManager.theSceneManager.unproyectPoint(worldPoint);
    	// Update the matrix of the geometry
    	//theGeometry.updateTransform(worldPoint.x, worldPoint.y, 0.0f);
    	// Render the geometry
    	renderer.setModelMatrix("u_modelView", theGeometry.theTransformation);

    	// Render the mesh
    	renderer.renderMesh(this.theGeometry.mesh, GL10.GL_TRIANGLES);
	}

  	public void updateTransform(float x, float y, float z) {
    	theTransformation.identity();

    	if (theOrigin.x != 0 || theOrigin.y != 0 || theOrigin.z != 0) {
        	theTransformation.setToTranslation(theOrigin);
    	}
    	if (theScale.x != 1 || theScale.y != 1 || theScale.z != 0) {
        	theTransformation.mult(theTempMatrix.setToScaling(theScale));
    	}
    	if (theOrigin.x != 0 || theOrigin.y != 0 || theOrigin.z != 0) {
        	theTransformation.mult(theTempMatrix.setToTranslation(-theOrigin.x, -theOrigin.y, -theOrigin.z));
    	}
    	if (x != 0 || y != 0 || z != 0) {
        	theTransformation.getValues()[6] += x;
        	theTransformation.getValues()[7] += y;
        	theTransformation.getValues()[8] += z;
    	}
	}

And the shader

    	String vertexShader =
              	"attribute vec4 a_position;\n" //
            	+ "attribute vec4 a_color;\n" //
            	+ "attribute vec2 a_texCoords;\n" //
            	+ "uniform mat4 u_projectionViewMatrix;\n" //
            	+ "uniform mat4 u_modelView;\n" //
            	+ "varying vec4 v_color;\n" //
            	+ "varying vec2 v_texCoords;\n" //
            	+ "\n" //
            	+ "void main()\n" //
            	+ "{\n" //
            	+ "   v_color = a_color;\n" //
            	+ "   v_texCoords = a_texCoords;\n" //
            	+ "   gl_Position = (u_projectionViewMatrix * u_modelView) * a_position;\n" //
            	+ "}\n";
    	String fragmentShader =
              	"#ifdef GL_ES\n" //
            	+ "precision mediump float;\n" //
            	+ "#endif\n" //
            	+ "varying vec4 v_color;\n" //
            	+ "varying vec2 v_texCoords;\n" //
            	+ "void main()\n"//
            	+ "{\n" //
            	+ " 	gl_FragColor = v_color;\n" //
            	+ "}";


Well thats all, i choose 3D isometric with 2D textures, because i want to able to use opengl lighthing or any other feature that needs a 3D object. Also is usefull for a physics simulation. I hope anyone can help me, and thanks!!!!

PARTNERS