Skip to content

Instantly share code, notes, and snippets.

View Nehon's full-sized avatar

Rémy Bouquet Nehon

  • Sketchfab, Epic Games
  • Toulouse, France
  • X @nehon_42
View GitHub Profile
export const overrides079Bugs = function(){
// Hot replace Compendium.updateEntity with a fixed version
/**
* Update a single Compendium entry programmatically by providing new data with which to update
* @param {Object} data The incremental update with which to update the Entity. Must contain the _id
* @param {Object} options Additional options which modify the update request
0: no_name (node), parent: -1
Local: 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
world: 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
1: lowpoly_tools.fbx (node), parent: 0
Local: 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
world: 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
2: RootNode (node), parent: 0
Local: 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
world: 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
3: adjustable_wrench_lod3 (node), parent: 0
void update(){ // as in the update we call on each frame, be it RAF or dopeUpdate
pollEvent();
Barrier updateBarrier;
scheduler.runTask(logicUpdate, updateBarrier); // launch the frame update task with a barrier
render(); // the actual render called on the main thread
scheduler.wait(updateBarrier);
render::swapQueues();
}
// single threaded : the logicUpdate will run before the render, and the wait after the render will have no effect.
// This small snipet is something I came with to have a set of functions that you can enable or disable.
// The requirement is to have minimum overhead when the function set is disabled, so NO if(!enabled) return; in each function.
// The idea is that for each function have instead an array of function pointer of 2 elements
funcPointer[2]{noop, implem};
// the first element is actually a noop function that does nothing, the second is the proper implemenation of the function
// With this in place you can do somthing like this
funcPointer[enabled]();
// With enabled being a boolean. This will call the noop function when the functionsst is disable (enabled = false or 0)
// and the proper implem when the function set is enabled (enable = true or 1).
using func = void(*)(GLuint);
const func bindVaoFunctions[] {emulateBindVAO, glBindVertexArray};
...
#ifdef __EMSCRIPTEN__
const int hasVAO = getWebglCaps().hasVAO;
bindVaoFunction[hasVao](vao);
#else
for (auto& sync : queue.syncList) {
dope::Scheduler* scheduler = sync.scheduler;
DOPE_ASSERT(scheduler != nullptr, "To use sync command buffer the sync needs to be initialized with a scheduler");
scheduler->decrementSync(&sync);
}
queue.syncList.clear();
using CommandAction = void (*)(const Command* command, DataGL* dataGl);
strcut Command{
// as the current command but with a pointer to impl
CommandAction execute;
}
// example create buffer
// in execute command
//load asset sync
MyAssetLoader loader; // stateful, unique usage loader
loadAsset(path, &loader);
// get the resulting data from loader depending on the implem
// for example
ecs.executeCommand(loader.commandBuffer);
//load asset async
MyAssetLoader* loader = newScopedObject<MyAssetLoader>().release(); // stateful, unique usage loader
Sync s;
Ctx* ctx = newScopedObject<Ctx>().release();
Sync s;
scheduler.runTask([ctx](){
// do some stuff with ctx
}, &s);
scheduler.runtaskAfter(&s, [ctx](){
// do stuff with ctx
mem.delete(ctx);
})
// Transform tree example
TransformNodesSystem transformTreeSystem;
TransformLeavesSystem transformLeavesSystem;
// First step: update squentially all nodes (can't be multithreaded as parents need to be updated before children
ecs // no lint
->beginSequentialTransaction()
.executeSystem(&transformTreeSystem)
.end();