Git Product home page Git Product logo

ocs's People

Contributors

ayebear avatar kevinwmiller avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

ayebear

ocs's Issues

Fix adding/removing while looping

There should be a better solution to this line in the PackedArray class:
PackedArray() {elements.reserve(100000);}

Maybe add some sort of queuing system so elements are only added/removed after looping.

Assertion failed

When running the test program, I'm getting this:
OCS_Test: Commands_Test.cc:116: void cmdtest::TEST_DESTROY_OBJECT_COMMAND(): Assertion `objManager.getTotalObjects() == 2' failed.

I checked the total number of objects, and it goes down to 1 after calling execute() on the same command twice. So it shouldn't be deleting an object with an invalid ID.

It could be an issue with PackedArray, or something else.

Named objects

Allow the use of string based names to identify objects in addition to IDs. It would be optional to register a name. Ideally, you could do it on object creation, so it could be done in 1 line.

Currently, I'm managing parallel maps along with all of the ObjectManager instances for my game, and it would make sense to include this feature in OCS.

auto id = objects.createObject("Prototype");
level.registerObjectName(id, "obj1");
...
auto id = level.getObjectIdFromName("obj1");
auto comp = objects.getComponent<Position>(id);

Would become:

auto id = objects.createObject("Prototype", "obj1");
...
auto comp = objects.getComponent<Position>("obj1");

PackedArray casing style

The casing style of the methods in PackedArray are inconsistent. I would propose switching everything to camelCase instead of snake_case. This would probably cause a lot of other code to have to change though.

Add full component string name support

Add support for removing, adding, assigning, etc. components using their bound string name. This will allow for better networking/file support.

Note: Could also add the ability to get components with their name, but it would have to be the base Component class reference, because you can't just change types in code on runtime.

Simplified iteration of components

Iterating over a few component types currently looks like this:

for (auto& velocity: objects.getComponentArray<Velocity>())
{
    auto ownerId = velocity.getOwnerID();
    auto position = objects.getComponent<Position>(ownerId);
    auto size = objects.getComponent<Size>(ownerId);
    auto aabb = objects.getComponent<AABB>(ownerId);
    if (position && size && aabb)
    {
        // Do stuff with components
    }
}

I wonder if there is an easier way that requires less typing, while still being cache efficient for the primary component type. One possible way is to integrate systems so that they process one object or tuple at a time (still keeping the order of the primary component type), and have the system manager use some filtering code and automatically call this when being updated.

A temporary solution could be to have a macro write most of the code for you:

ocs_forEachObject(Velocity, velocity, Position, position, Size, size, AABB, aabb)
{
    // Do stuff with components
}

But that would require a variadic macro that does something different for each parameter. So you'd have to have a version for each amount of parameters. And getting the curly braces right would be tricky, unless you had a "begin" and "end" for the loop.

Implement an assignComponent() method

This would be part of the ObjectManager. It would check if the component exists, add a new one if it doesn't, or set it if it does.

This would cover most use cases, since add/set won't always work depending on if the component already exists. Most of the time you'd want to just replace it.

Update: Unless you can show me use cases for "add" and "set" when there is an "assign", then you could probably remove them from the public interface.

Component name binding

Make binding names to component types cleaner and easier to do. One possible way is to have a static getName function for components. This way, you could optionally define getName, and inside of the registerComponent function, it would bind the name if needed.

Edit: This would probably only work if you initially added all of the components though.

Component handles

Add support for safe component "handles" instead of using raw pointers to vector elements which could be invalidated. They could contain a pointer/reference to the PackedArray instance, and an ID to the element in the internal vector.

A possibly more generic solution would be to add a smart handle to PackedArray, which would contain "this" and the ID. But it would work like a normal pointer, with the * and -> operators.

Basically, just try to solve this problem:

auto obj1 = objects.createObject();
auto obj2 = objects.createObject();

objects.addComponents<Position>(obj1);
auto pos1 = object.getComponent<Position>(obj1);

objects.addComponents<Position>(obj2);
auto pos2 = object.getComponent<Position>(obj2);

pos1->x = 0; // This *could* fail, if the component array resized after adding the second component

Feature request: Updating components using bound string name

It would be great if you could update components using an object's ID, the component's name as a string, and a string to deserialize data from. It already supports binding names to components.

Also, "update" means creating a new component if it doesn't exist, and then setting the component (calling deserialize). This would be more convenient than having the user do these steps all the time.

The reason I need this feature is for the level loading code in my game. That way I can just override the components with everything in the level file, since objects will vary across levels. It would probably be useful in other cases too, such as synchronizing components/objects across a network.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.