• Create Account

# Wolftein

Member Since 13 Jun 2011
Offline Last Active Mar 04 2016 11:02 AM

### In Topic: Optimization of a method

12 October 2013 - 06:43 PM

You could implement the voxel storage as a tree, each leaf is connected another leaf, only if that block is adjacent. Then when you add or remove block dynamic you could just go the the leaf where the near block is at and attach it or just add a new leaf if it doesn't have adjacent blocks. You could also use divide and conquer and divide those chunks in small pieces and calculate them parallel. The method it self can be optimized if you pre-cache the position

```if (cube.World.Translation.Z + 0.5f != adjacentCube.World.Translation.Z - 0.5f)
{
break;
}
if (cube.World.Translation.Z - 0.5f != adjacentCube.World.Translation.Z + 0.5f)
{
break;
}```
```auto bZ1 = cube.World.Translation.Z - 0.5f;
auto bZ2 = cube.World.Translation.Z + 0.5f;
auto cZ1 = adjacentCube.World.Translation.Z - 0.5f;
auto cZ2 = adjacentCube.World.Translation.Z + 0.5f;

if (bZ1 != cZ2 || bZ2 != cZ1 || ....)
```

But like Batterius said, its the design rather than the method.

### In Topic: Component based system

30 September 2013 - 07:29 PM

You can check out my library too if you please. https://github.com/miguelishawt/anax

Check the wiki for a basic tutorial on how to use it.

Your library seems very well designed, i will take a look at it . Thanks everybody!

### In Topic: A Resource manager design.

17 September 2013 - 02:43 PM

I recently finished my Resource Module as well, I'm going to post the design here so you can get your own thoughts of it.

It's very similar to yours too.

Resource Classes:

First, I have these [Basic Types]: MeshClass, MaterialClass, TextureClass, and anything else that I might add.

They contain only the resource data of how a Mesh if defined, the values of a Material, the Texture image, etc

Then I have the [Info Types]: ImageClass, ModelClass, and still adding new stuff.

These don't contain any data except the IDs/Names of what compose a Image or a Model.

Each one of the above have their own functions to load and save their data.

So I can create new Texture objects from BMPs, PNGs or anything else, and I save them in a format of my own.

And finally, the actual resource classes of: SpriteImage, Model, etc

An Image has an imageClass variable that describes what composes it: a TextureClass, a Material and a Canvas.

Resource Cache:

This class accepts any template, gives it an int for ID and a string for name, and puts it in a vector.

Actually I have two vectors in this one, one for headers, another one for objects.

When I open a resource file in my format from, I read only the headers and save them in the vector.

Then when a resource is requested, I'm surely to return a pointer to the resource, and I go through these steps:

- First, look in the loadedResources vector. If the requested ID/name is already there, return it.

- If not, look in the headerResources vector. I'll find the header based on ID/name, if not I'll throw an error to my error module and return 0;

- If I found the header, I'll create a new object of the requested type, call it's LoadFromResource() function, add to my loadedResources vector, and return it's pointer.

I also left an AddResource() function if I want to load outside the resource manager for some (weird) reason, so it can start to manage it.

It'll free the memory/destroy the objects when it goes out of scope, so I don't have about leaks (I just have to properly delete stuff I allocated in these objects).

Also, this class has a Save() function that will loop through all loaded objects and save it to a file by calling each of the object's SaveToResource() function.

This is so I can get a single file with all resources of the same type, organized with headers, for easier loading the next time.

It also have the Load() (obviously) to accompany it...

Resource Manager:

Then I have this Resources class that has a bunch of template functions, and it's the class that knows how to load each type of resource.

For example, when I call Resources.Load<Image>("imageName"); it'll need to know how an image is loaded:

- First, look in the ResourceCache<ImageClass> to get that particular image's texture, material and canvas size.

- Then load every one of the resources that compose it from the other (Basic Types) ResourceCaches: Texture, Material, Canvas (this one actually I don't keep track, I create a new one everytime a new image is loaded so I can change it without worrying about messing with other images).

I had a hard time coming up with something to handle composite resources, and that's what I came up with.

For example, I might want to have two of the same 3D Model but with a different texture each, so I also had to keep track of each of these models remembering which texture/mesh they had.

For the case that I want a new copy of something that will be changed (such as material), I just create a new one in the Resources's Load function:

```template <> Image* Load(int imageID)
{
Image* image = new Image();
image->_imageInfo = _imageInfoVector.GetResource(imageID);

if(image->_imageInfo != 0)
{
image->Texture = _textures.GetResource(image->_imageInfo.textureID);
//Texture shares the same pointer since I won't change them per image

image->Material = new Material(_materials.GetResource(image->_imageInfo.materialID));
//But I will for the material, so I create a new one, and I copy it through a constructor overload
//So I can change this image's material without it affecting any other images

//Whatever else my image will have
}

return image;
};
```

Hope this help give you some ideas on how to design yours.

Thank you, that gave me a lots of ideas on how could i improve my design.

### In Topic: implementing scripting

17 September 2013 - 02:36 PM

For communication between DLL's and EXE's using C++ a commonly used technique is to have virtual interfaces to systems, as this way you can pass around a pointer to a structure which holds the pointers to the interface of each sub system. This is the technique we used in Runtime Compiled C++ and it's also how the CryENGINE passes around interfaces using gEnv.

For a look at what a system table looks like see this file.

Exporting classes without using virtual interfaces is not simple in general, for an overview have a look at this post on codeproject. Using a virtual interface makes things alot easier - they don't have to be pure virtual but this does help to eliminate mistakes. Make sure to define a virtual destructor to prevent the memory created in one module being freed in another.

Feel free to use any of the code in RCC++, we use a liberal Zlib license and you can just use which-ever parts you need.

I just knew about Runtime Compiled C++ and must say, wow, amazing idea.

### In Topic: This beauty...

17 September 2013 - 01:17 PM

Who ever coded that doesn't know what "funroll-all-loops" is and tried to achieve same result by hand.

PARTNERS