Pixel-Composer/scripts/render_data/render_data.gml

134 lines
3.4 KiB
Text
Raw Normal View History

enum RENDER_TYPE {
none = 0,
partial = 1,
full = 2
}
2022-12-13 09:20:36 +01:00
global.RENDER_LOG = false;
2022-01-24 02:21:25 +01:00
function __nodeLeafList(_list, _stack) {
for( var i = 0; i < ds_list_size(_list); i++ ) {
var _node = _list[| i];
2022-12-13 09:20:36 +01:00
if(!_node.active) continue;
2022-12-18 03:20:38 +01:00
var _startNode = _node.isRenderable(true);
2022-12-13 09:20:36 +01:00
if(_startNode) {
ds_stack_push(_stack, _node);
printIf(global.RENDER_LOG, "Push node " + _node.name + " to stack");
2022-01-24 02:21:25 +01:00
}
}
}
2022-12-16 09:18:09 +01:00
function __nodeInLoop(_node) {
var gr = _node.group;
while(gr != -1) {
if(instanceof(gr) == "Node_Iterate") return true;
if(instanceof(gr) == "Node_Feedback") return true;
gr = gr.group;
}
return false;
}
2022-12-10 05:06:01 +01:00
function Render(partial = false) {
2022-01-13 05:24:03 +01:00
var rendering = noone;
2022-01-24 02:21:25 +01:00
var error = 0;
2022-12-13 09:20:36 +01:00
printIf(global.RENDER_LOG, "=== RENDER START ===");
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
if(!partial || ALWAYS_FULL) {
2022-12-10 05:06:01 +01:00
var _key = ds_map_find_first(NODE_MAP);
var amo = ds_map_size(NODE_MAP);
2022-12-16 09:18:09 +01:00
2022-12-10 05:06:01 +01:00
repeat(amo) {
var _node = NODE_MAP[? _key];
2022-12-13 09:20:36 +01:00
_node.setRenderStatus(false);
2022-12-10 05:06:01 +01:00
_key = ds_map_find_next(NODE_MAP, _key);
}
}
// get leaf node
ds_stack_clear(RENDER_STACK);
var key = ds_map_find_first(NODE_MAP);
var amo = ds_map_size(NODE_MAP);
repeat(amo) {
var _node = NODE_MAP[? key];
key = ds_map_find_next(NODE_MAP, key);
if(is_undefined(_node)) continue;
if(!is_struct(_node)) continue;
if(instanceof(_node) == "Node_Group_Input") continue;
if(instanceof(_node) == "Node_Iterator_Input") continue;
2022-12-13 09:20:36 +01:00
if(!_node.active) continue;
if(_node.rendered) continue;
2022-12-16 09:18:09 +01:00
if(__nodeInLoop(_node)) continue;
2022-12-13 09:20:36 +01:00
2022-12-18 03:20:38 +01:00
var _startNode = _node.isRenderable();
2022-12-13 09:20:36 +01:00
if(_startNode) {
ds_stack_push(RENDER_STACK, _node);
printIf(global.RENDER_LOG, " > Push " + _node.name + " node to stack");
2022-12-10 05:06:01 +01:00
}
}
2022-01-24 02:21:25 +01:00
// render forward
while(!ds_stack_empty(RENDER_STACK)) {
rendering = ds_stack_pop(RENDER_STACK);
2022-01-24 02:21:25 +01:00
2022-12-13 09:20:36 +01:00
var txt = rendering.rendered? " [Skip]" : " [Update]";
2022-12-12 09:08:03 +01:00
if(!rendering.rendered) {
if(LOADING || APPENDING || rendering.auto_update)
rendering.doUpdate();
rendering.setRenderStatus(true);
2022-01-13 05:24:03 +01:00
}
2022-12-13 09:20:36 +01:00
printIf(global.RENDER_LOG, "Rendered " + rendering.name + " [" + string(instanceof(rendering)) + "]" + txt);
2022-12-16 09:18:09 +01:00
rendering.getNextNodes();
2022-01-13 05:24:03 +01:00
}
2022-12-12 09:08:03 +01:00
2022-12-13 09:20:36 +01:00
printIf(global.RENDER_LOG, "=== RENDER COMPLETE ===\n");
2022-01-13 05:24:03 +01:00
}
/*
function renderNodeBackward(_node) { //unused
var RENDER_STACK = ds_stack_create();
ds_stack_push(RENDER_STACK, _node);
2022-01-13 05:24:03 +01:00
var key = ds_map_find_first(NODE_MAP);
for(var i = 0; i < ds_map_size(NODE_MAP); i++) {
var _allnode = NODE_MAP[? key];
if(_allnode && !is_undefined(_allnode) && is_struct(_allnode) && string_pos("Node", instanceof(_allnode)))
2022-12-12 09:08:03 +01:00
_allnode.triggerRender();
2022-01-13 05:24:03 +01:00
key = ds_map_find_next(NODE_MAP, key);
}
for(var i = 0; i < ds_list_size(_node.inputs); i++) {
var _in = _node.inputs[| i];
if(_in.value_from) {
ds_stack_push(RENDER_STACK, _in.value_from.node);
2022-01-13 05:24:03 +01:00
}
}
while(!ds_stack_empty(RENDER_STACK)) {
var _rendering = ds_stack_top(RENDER_STACK);
2022-01-13 05:24:03 +01:00
var _leaf = true;
for(var i = 0; i < ds_list_size(_rendering.inputs); i++) {
var _in = _rendering.inputs[| i];
if(_in.value_from && !_in.value_from.node.rendered) {
ds_stack_push(RENDER_STACK, _in.value_from.node);
2022-01-13 05:24:03 +01:00
_leaf = false;
}
}
if(_leaf) {
//show_debug_message("Rendering " + _rendering.name + " at " + string(ANIMATOR.current_frame));
2022-01-23 04:08:16 +01:00
_rendering.setRenderStatus(true);
2022-01-13 05:24:03 +01:00
if(_rendering.use_cache) {
if(!_rendering.recoverCache())
_rendering.doUpdate();
2022-01-13 05:24:03 +01:00
} else
_rendering.doUpdate();
ds_stack_pop(RENDER_STACK);
2022-01-13 05:24:03 +01:00
}
}
ds_stack_destroy(RENDER_STACK);
2022-01-13 05:24:03 +01:00
}