2022-01-25 04:05:30 +01:00
|
|
|
enum RENDER_TYPE {
|
|
|
|
none = 0,
|
|
|
|
partial = 1,
|
|
|
|
full = 2
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
if(_node.active && !is_undefined(_node) && is_struct(_node)) {
|
|
|
|
var _startNode = true;
|
|
|
|
for(var j = 0; j < ds_list_size(_node.inputs); j++) {
|
|
|
|
var _in = _node.inputs[| j];
|
2022-12-12 09:08:03 +01:00
|
|
|
_node.triggerRender();
|
2022-01-24 02:21:25 +01:00
|
|
|
|
|
|
|
if(_in.value_from != noone)
|
|
|
|
_startNode = false;
|
|
|
|
}
|
|
|
|
if(_startNode)
|
|
|
|
ds_stack_push(_stack, _node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(!partial) {
|
|
|
|
var _key = ds_map_find_first(NODE_MAP);
|
|
|
|
var amo = ds_map_size(NODE_MAP);
|
|
|
|
|
|
|
|
repeat(amo) {
|
|
|
|
var _node = NODE_MAP[? _key];
|
2022-12-12 09:08:03 +01:00
|
|
|
_node.triggerRender();
|
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;
|
|
|
|
|
|
|
|
if(_node.active && !_node.rendered) {
|
|
|
|
var _startNode = true;
|
|
|
|
for(var j = 0; j < ds_list_size(_node.inputs); j++) {
|
|
|
|
var _in = _node.inputs[| j];
|
|
|
|
if(_in.value_from != noone && !_in.value_from.node.rendered)
|
|
|
|
_startNode = false;
|
|
|
|
}
|
|
|
|
if(_startNode)
|
|
|
|
ds_stack_push(RENDER_STACK, _node);
|
|
|
|
}
|
|
|
|
}
|
2022-01-24 02:21:25 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var log = false;
|
|
|
|
printlog("=== RENDER START ===");
|
2022-01-16 05:17:35 +01:00
|
|
|
// render forward
|
2022-01-25 04:05:30 +01:00
|
|
|
while(!ds_stack_empty(RENDER_STACK)) {
|
|
|
|
rendering = ds_stack_pop(RENDER_STACK);
|
2022-01-24 02:21:25 +01:00
|
|
|
|
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-12 09:08:03 +01:00
|
|
|
printlog("Rendered " + rendering.name);
|
2022-01-24 02:21:25 +01:00
|
|
|
|
|
|
|
if(instanceof(rendering) == "Node_Group") { //Put each input node in group to stack
|
2022-12-12 09:08:03 +01:00
|
|
|
//if(!rendering.isUpdateReady()) continue;
|
2022-01-24 02:21:25 +01:00
|
|
|
for(var i = rendering.custom_input_index; i < ds_list_size(rendering.inputs); i++) {
|
|
|
|
var _in = rendering.inputs[| i].from;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
ds_stack_push(RENDER_STACK, _in);
|
|
|
|
printlog("Push group input " + _in.name + " to stack");
|
2022-01-23 04:08:16 +01:00
|
|
|
}
|
2022-01-24 02:21:25 +01:00
|
|
|
} else if(instanceof(rendering) == "Node_Group_Output") { //Group output in-junction connect automatically to parent out-junction
|
2022-12-12 09:08:03 +01:00
|
|
|
rendering.group.setRenderStatus(true);
|
2022-01-18 05:31:19 +01:00
|
|
|
var _ot = rendering.outParent;
|
2022-12-12 09:08:03 +01:00
|
|
|
printlog("Value to amount " + string(ds_list_size(_ot.value_to)));
|
2022-01-23 04:08:16 +01:00
|
|
|
for(var j = 0; j < ds_list_size(_ot.value_to); j++) {
|
|
|
|
var _to = _ot.value_to[| j];
|
2022-12-12 09:08:03 +01:00
|
|
|
printlog("Value to " + _to.name);
|
|
|
|
if(!_to.node.active || _to.value_from == noone) {
|
|
|
|
printlog("no value from");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(_to.value_from.node != rendering.group) {
|
|
|
|
printlog("value from not equal group");
|
|
|
|
continue;
|
|
|
|
}
|
2022-01-23 04:08:16 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
printlog("Group output ready " + string(_to.node.isUpdateReady()));
|
|
|
|
//_to.node.triggerRender();
|
|
|
|
if(_to.node.isUpdateReady()) {
|
|
|
|
ds_stack_push(RENDER_STACK, _to.node);
|
2022-01-23 04:08:16 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-24 02:21:25 +01:00
|
|
|
} else if(instanceof(rendering) == "Node_Iterate") { //Put each input node in group to stack
|
|
|
|
for(var i = rendering.custom_input_index; i < ds_list_size(rendering.inputs); i++) {
|
|
|
|
var _in = rendering.inputs[| i].from;
|
2022-01-25 04:05:30 +01:00
|
|
|
if(_in.isUpdateReady()) ds_stack_push(RENDER_STACK, _in);
|
2022-01-24 02:21:25 +01:00
|
|
|
}
|
|
|
|
} else if(instanceof(rendering) == "Node_Iterator_Output") { //Check iteration result
|
2022-01-23 04:08:16 +01:00
|
|
|
var _node_it = rendering.group;
|
2022-12-12 09:08:03 +01:00
|
|
|
var _ren = _node_it.iterationStatus();
|
2022-01-23 04:08:16 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(_ren == ITERATION_STATUS.loop) { //Go back to the beginning of the loop, reset render status for leaf node inside?
|
2022-01-25 04:05:30 +01:00
|
|
|
//show_debug_message("iteration restart");
|
2022-01-23 04:08:16 +01:00
|
|
|
var _ot = rendering.group.inputs;
|
2022-12-12 09:08:03 +01:00
|
|
|
for(var j = rendering.group.custom_input_index; j < ds_list_size(_ot); j++) {
|
2022-01-25 04:05:30 +01:00
|
|
|
if(_ot[| j].from.isUpdateReady()) ds_stack_push(RENDER_STACK, _ot[| j].from);
|
2022-01-23 04:08:16 +01:00
|
|
|
}
|
2022-01-24 02:21:25 +01:00
|
|
|
|
2022-01-25 04:05:30 +01:00
|
|
|
__nodeLeafList(rendering.group.nodes, RENDER_STACK);
|
2022-12-12 09:08:03 +01:00
|
|
|
} else if(_ren == ITERATION_STATUS.complete) { //Go out of loop
|
2022-01-25 04:05:30 +01:00
|
|
|
//show_debug_message("iteration completed");
|
2022-12-12 09:08:03 +01:00
|
|
|
rendering.group.setRenderStatus(true);
|
2022-01-23 04:08:16 +01:00
|
|
|
var _ot = rendering.outParent;
|
2022-01-18 05:31:19 +01:00
|
|
|
for(var j = 0; j < ds_list_size(_ot.value_to); j++) {
|
|
|
|
var _to = _ot.value_to[| j];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
if(_to.node.active && _to.value_from != noone && _to.value_from.node == rendering.group) {
|
2022-12-12 09:08:03 +01:00
|
|
|
_to.node.triggerRender();
|
2022-01-25 04:05:30 +01:00
|
|
|
if(_to.node.isUpdateReady()) ds_stack_push(RENDER_STACK, _to.node);
|
2022-01-18 05:31:19 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-24 02:21:25 +01:00
|
|
|
} else { //push next node
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < ds_list_size(rendering.outputs); i++) {
|
|
|
|
var _ot = rendering.outputs[| i];
|
|
|
|
|
|
|
|
for(var j = 0; j < ds_list_size(_ot.value_to); j++) {
|
|
|
|
var _to = _ot.value_to[| j];
|
2022-12-12 09:08:03 +01:00
|
|
|
if(!_to.node.active || _to.value_from == noone) continue;
|
|
|
|
if(_to.value_from.node != rendering) continue;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
_to.node.triggerRender();
|
|
|
|
if(_to.node.isUpdateReady()) {
|
|
|
|
ds_stack_push(RENDER_STACK, _to.node);
|
|
|
|
printlog("Push " + _to.node.name + " node to stack");
|
|
|
|
} else
|
|
|
|
printlog(" > Node " + _to.node.name + " not ready");
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-24 02:21:25 +01:00
|
|
|
|
|
|
|
//show_debug_message(txt);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-12-12 09:08:03 +01:00
|
|
|
|
|
|
|
printlog("=== RENDER COMPLETE ===");
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-01-25 04:05:30 +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) {
|
2022-01-25 04:05:30 +01:00
|
|
|
ds_stack_push(RENDER_STACK, _in.value_from.node);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 04:05:30 +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) {
|
2022-01-25 04:05:30 +01:00
|
|
|
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())
|
2022-01-16 14:28:57 +01:00
|
|
|
_rendering.doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
} else
|
2022-01-16 14:28:57 +01:00
|
|
|
_rendering.doUpdate();
|
2022-01-25 04:05:30 +01:00
|
|
|
ds_stack_pop(RENDER_STACK);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 04:05:30 +01:00
|
|
|
ds_stack_destroy(RENDER_STACK);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|