Jump to content
  • Advertisement

Aqua Costa

Member
  • Content Count

    1002
  • Joined

  • Last visited

Community Reputation

3703 Excellent

About Aqua Costa

  • Rank
    Crossbones+

Personal Information

Social

  • Twitter
    TiagoCostaV

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Aqua Costa

    C++: Custom memory allocation

    Do you want every thread to allocate from the same block of memory? If so you'll probably need to add a lock to the allocator (maybe in a wrapper similar to the ProxyAllocator).   In my engine, threads don't usually allocate memory from a global allocator, instead they use separate allocators (each allocator manages a separate chunk of memory) so no there's no need for locks in most cases.
  2. Aqua Costa

    C++: Custom memory allocation

    Hi,   alignForwardAdjustmentWithHeader calculates the adjustment required to align address and is at least headerSize.   Example: address = 13 alignment = 4 and the size of the allocation header is 6 bytes.   alignForwardAdjustment would return 3, but that's not enough to store the header.   So alignForwardAdjustmentWithHeader returns 3+4=7 enough to store the header and properly align the address.     No, because neededSpace and alignment are ints, so a integer division will be performed.   Example: 2 * 5/2 = 4   So  //Increase adjustment to fit header adjustment += alignment * (neededSpace / alignment); if(neededSpace % alignment > 0) adjustment += alignment; is basically calculating adjustment += alignment * ceil((float)neededSpace/(float)alignment) Does it make sense?
  3. Aqua Costa

    C++: Custom memory allocation

    An alignment of 0 makes no sense, so yes it will probably cause issues. I updated the ASSERT to prevent allocations with an alignment of 0.   You're right, there were some errors in the deallocate function of FreeListAllocator, I rewritten the function (the free blocks are now ordered btw), I've tested it a bit and some cases that caused errors in the previous version are now fixed. Feel free to test it yourself and give me some feedback :)
  4. Aqua Costa

    Implementing Component-Entity-Systems

    Great article!   I would suggest moving the looping through all entities and masking inside each system function. Try to follow Mike Acton's tip "Where there's one, there's more than one."  Before you know it, with the current implementation you will be calling each system function thousands of times every frame. #define THIS_SYSTEM_MASK 0x12345678 void movementFunction(World *world) { unsigned int entity;     for(entity = 0; entity < ENTITY_COUNT; ++entity)     { // The most important line in the implementation!         if((world->mask[entity] & THIS_SYSTEM_MASK) == THIS_SYSTEM_MASK) { Displacement *d = &(world->displacement[entity]); Velocity *v = &(world->velocity[entity]); v->y -= 0.98f; d->x += v->x; d->y += v->y; } } void runSystem(System *system, World *world) { system->function(world); } You don't even need a System struct, it can simply be a function.   And then again you can also remove the runSystem function and simply run each system directly, but since you probably won't have that many systems the perfomance impact will be smaller.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!