Jump to content

  • Log In with Google      Sign In   
  • Create Account


TheChubu

Member Since 13 Sep 2012
Offline Last Active Today, 03:54 AM
***--

Topics I've Started

Editor ate half of my journal entry

30 June 2014 - 08:40 PM

There I was, writing, editing, when It happened... I hit "save draft" button, and saw what was left of my entry. It ate half of it, maybe more.

 

I am not pleased. I am the opposite of pleased actually, to put it mildly. Where do I ask for 2 hours of my life back?


Can't access the site.

09 June 2014 - 06:06 PM

Well, I can access it from here, but in my home I cant.

 

Tried with Chrome 35 and 37, and with Iceweasel (Firefox) 29. I'm using Debian Jessie x64.

 

Chrome says "connecting..." for a while, then it stops loading and says the page can't be reached. Funnily enough, if I try to access gdnet from my phone in the same network, I can read the mobile version (I doubt the thing could handle the whole page), but logging in fails, I put my nick and password, and it returns me to the main page without getting logged in.

 

Its some sort of IP blacklisting or something? huh.png


Memory allocator. Maintaining free list.

01 June 2014 - 06:42 PM

Hi! I have some issues trying to implement a (sort of) memory allocator, it has to be tailored to the peculiarities of Java.

 

First and foremost, I'll describe what I have in Java instead of malloc() and friends:

 

Direct ByteBuffers, they're an object representing a chunk of memory outside JVM's heap, so it can't be moved by GC. They're used for interacting with native libraries (such as OpenGL, or Bullet). ByteBuffers expose methods for putting things into the buffer, they have a capacity and with some magical casting, you can free them manually.

 

ByteBuffers, unlike Java arrays, can be sliced via "byteBuffer.slice()" method. You get a ByteBuffer slice starting at the current position mark of the ByteBuffer, and a capacity equal to the remaining bytes in the backing buffer.

 

So what I wanted to do is the following:

 

Have a BufferAllocator that would allocate a big backing buffer (couple of MBs), and that it would manage slices of the backing buffer, so to avoid allocating/deallocating small buffers all over the codebase. "capacity" field of the slice can't be modified, so I modify it by reflection, so the user of the returned slice can't step on the memory that lies beyond their slice.

 

The ByteBuffer doesn't "knows" how much of it is being used. It only has a position mark, a limit mark, and a capacity. You write data into it however you want. So to manage the backing buffer I need an additional structure that can represent which parts of it are free and which parts of it are being used.

 

I decided to try a simple ArrayList of int[] arrays of size 2 representing the "free block list". First element of the int array is the offset of the block, second element is the end of the block.

 

Say that I want to ask for a 32 byte buffer, the allocator has 1KB capacity.

 

The allocator starts with a free block list containing a single element, a int[] with 0 as start value, and 1024 as the end value.

The allocator finds the smallest free block that can hold the 32 byte buffer it was asked for (ie, the only free block we have).

The allocator makes a slice starting at the free block start, ending at the 32 byte mark.

There is still a single contiguous free block, but now it starts at the 32 byte mark, and ends at the 1024 byte mark.

A ByteBuffer slice with capacity 32 is returned.

 

Have in mind this free block list is just a list of values to do the free block bookkeeping, not the actual memory.

 

Now, to "free" a ByteBuffer slice, I'd need to find roughly its position inside the free block list.

If there is a neighbor free block (ie, the freed block isn't between two used blocks), I'd need to modify its start/end offsets as required.

Otherwise, create a new int[] instance that holds the freed block's start and end offsets, then insert it into the free block list.

 

The problem is that if the block I'm trying to free is between two free blocks, I'd need to merge all 3 (left free block, the block I'm freeing, and the right free block). That would mean, removing one of the adjacent free blocks, and expanding the remaining one to cover the block I removed and the block I'm freeing.

 

Both things: I'm not sure how to do that without a chain of 10 if/else statements (hell, I even tried with lots of if/else statements and I still can't get it to work). And I'm obviously not making the most efficient lookup for finding free blocks to slice.

 

Here is my (broken) implementation so far:

 

http://paste.ofcode.org/3rJEwJtLx2L96KVBX8WX5e

 

Any help?


Assembling entities in an ECS? Scripting languages?

06 April 2014 - 02:37 AM

Hi!

 

I'm working on a little 3D project of mine using an Entity Component System framework (specifically, a modified version of Artemis). It's working fairly well for me, but I'm having some issues with regular "entity assembling".

 

As a note, its a very "textbook" implementation of an ECS. Entities are just IDs with Components, Components have just data, and Systems iterate over all Entities that have the components they're interested in. Everything is held by a "World" instance, there is where you hook up your Systems.

 

So, Entities are assembled out of Components, this example below is for creating a simple quad that has texture:

Entity e = world.createEntity()

.addComponent( new Orientation() )
.addComponent( new WorldTransform() )
.addComponent( new MVPTransform() )
.addComponent( new RenderState() );
.addComponent( quadGeometry )
.addComponent( new AABSquare( OpsMesh.getMinAABS( quadGeometry.vertexBuffer.view ) ) )
.addComponent( resourceManager.get( Texture.class, "testTexture.dds" ) )
.addComponent( Material.TEXTURED_NO_SHADING )
.addComponent( Tags.Static.VALUE )
.addComponent( Tags.Textured.VALUE );
e.addToWorld();

After those lines, the entity is already in the world and it will be processed by the systems that are interested in it.

 
Now, this is a very, very simple entity. Its literally a quad floating in the screen, and you can already see that the initialization is quite cumbersome. For example, if the mesh was rendered using indexed drawing, I'd need to add a GeometryIndices component, and change the Tags.Textured.VALUE for Tags.TexturedIndexed.VALUE. Quite annoying.
 
I was going to ask, how would I manage all of this in a more pleasant way? I already have an "EntityFactory" static that has methods like "genSpatial()" which returns an Entity with some Components used in spatials. But it seems like a band-aid rather than a proper solution, and it gets quite big after a few variants of spatials are added (dynamic spatial or static spatial? its textured or not? and so on...).
 
I thought about maybe creating some sort of "Bundle" of components? I'm not sure it would really help.
 
After thinking about it, it occurred to me that maybe this kind of work is done on a higher level language, so adding a scripting language hook and deal with this there might be a better idea. I have no experience with scripting languages though, so I'm not sure how to get that working (I'm using Java, I have various choices, Python 2.7, Lua, Javascript, etc. I'm only barely familiar with Python though).
 
This also ties in with something I haven't got around to do yet: Scene management. This would involve having some way to define a scene, with all its Entities, and what are those Entities composed from, outside the application, so I can load/unload them. For starting with that though, I'd prefer to have some clean way to assemble Entities first...

Thread-safe unique sequential index per class

08 February 2014 - 12:28 PM

Hi! So I was hacking a bit the Java Artemis ECS framework  (ECS = Entity component system) and noticed something: There are two parts of it that require unique integer indices per class, not per object instance.

 

It needs an unique index for each class that extends Component (ComponentType serves this purpose) and for each class that extends EntitySystem (the SystemIndexManager static inside EntitySystem serves this purpose).

 

Both solutions more or less rely on a HashMap storing the relationship between a class and its index.

 

(EntitySystem class source and ComponentType source for reference)

 

Both are unsafe in multi threading usage, meaning that if you either add components of the same type to two separate entities in different threads or create EntitySystem objects in different threads, you get non-deterministic results.

 

First instinct was to replace the static ints for AtomicIntegers, yet that doesn't makes it thread safe since there is a whole method and a HashMap in the middle.

 

So I am asking how would I implement an unique index per class. It doesn't has to be unique in itself but unique indices for EntitySystems and unique indices for ComponentTypes separately. It has to be sequential since those are used for direct array access on various places (so I can't have an EntitySystem with an index of 3 million for example).

 

I could use synchronized methods and ConcurrentHashMap, following the same ideas of Artemis, but its possible that there is a lock-free way to do this? Or at least least intrusive than synchronizing related methods? As I mentioned, I'm using Java so there are quite a bit of threading stuff to use.


PARTNERS