Giter VIP home page Giter VIP logo

koora's Issues

Linear Component Array Memory Layout

It'd be great to explore a method for laying out the data of components in a 'linear' manner, as seen in the sparse set ECS approach. I originally had ideas about using Typed Arrays for all primitives in components, because I have some understanding of how to get them to all share the same ArrayBuffer, but as @MaxGraey points out in PR #1 this is less than ideal due to the extra layer of abstraction.

I would love to learn how this can be achieved in AssemblyScript, I suppose the ideal solution would have the following:

  • Reserve a chunk of memory for an array of components
  • Specify a location/offset when a class is allocated
  • Provide a way to pass this to the javascript WebGL API
  • Allow the underlying chunk to be resized/reallocated?

Here's an example to hopefully clarify the problem that I'm having:

class MyComponent{
  valA: f32
  valB: Vector3
  static byteStride: u16 = 32 // could this be auto generated?

}

const initialComponentCount = 10
//this is my imaginary alternative to ArrayBuffer
const componentPool = new MemoryAllocation(MyComponent.byteStride * initialComponentCount)

function addComponentToPool(index: u16){
  //somehow the new instance is assigned to that location in memory
  componentPool.set(new MyComponent(), MyComponent.byteStride * index)
}

function getComponentAtIndex(index:u16):MyComponent{
  return componentPool.get(MyComponent.byteStride * index)
}

function doJavascriptWebGLThingWithComponent(index:u16){
  // it may be better to do this cast in JS, so that we dont need to copy the data across on each usage
  const poolAsBufferView = Uint8Array.from(componentPool)
  const byteOffset = MyComponent.byteStride * index
  gl.bufferData(gl.ArrayBuffer,poolAsBufferView,gl.STATIC_DRAW,byteOffset,MyComponent.stride)
}
  • note: it looks like according to this stack overflow, passing in a Uint8Array as a view for data that may actually be floats etc is ok

Edit: Just discovered the following functions, perhaps some combination may do the trick:

export declare function load<T>(ptr: usize, immOffset?: usize, immAlign?: usize): T;
export declare function store<T>(ptr: usize, value: auto, immOffset?: usize, immAlign?: usize): void;
export declare function sizeof<T>(): usize; // | u32 / u64
export declare function alignof<T>(): usize; // | u32 / u64
export declare function offsetof<T>(fieldName?: string): usize; // | u32 / u64
export declare function changetype<T>(value: auto): T;

Congrats

I found no other channel :D

Just wanted to say congratulations for your success with this project.
I've been working with AS in 2019 and doing some 3D / animation stuff.

I'd love to see this project evolving as I'm probably one of the developers who are in the perfect target group for a project like this. I'd love to create 3D scenes and small-scale games, but I'm absolutely not ready to jump into hardcore 3D game development with C++ and alike.

So thanks alot and I wish you success!!
Please don't let yourself get demotivated ... every start is hard

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.