Pixel-Composer/scripts/render_data/render_data.gml

192 lines
5.7 KiB
Text
Raw Normal View History

enum RENDER_TYPE {
none = 0,
partial = 1,
full = 2
}
2022-01-23 04:08:16 +01:00
function renderAll() {
2022-01-13 05:24:03 +01:00
var _key = ds_map_find_first(NODE_MAP);
2022-01-23 04:08:16 +01:00
var amo = ds_map_size(NODE_MAP);
2022-01-13 05:24:03 +01:00
2022-01-23 04:08:16 +01:00
repeat(amo) {
2022-01-13 05:24:03 +01:00
var _node = NODE_MAP[? _key];
2022-01-23 04:08:16 +01:00
_node.setRenderStatus(false);
2022-01-13 05:24:03 +01:00
_key = ds_map_find_next(NODE_MAP, _key);
}
ds_stack_clear(RENDER_STACK);
// get leaf node
var key = ds_map_find_first(NODE_MAP);
repeat(ds_map_size(NODE_MAP)) {
var _node = NODE_MAP[? key];
key = ds_map_find_next(NODE_MAP, key);
if(instanceof(_node) == "Node_Group_Input") continue;
if(instanceof(_node) == "Node_Iterator_Input") continue;
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];
if(_in.value_from != noone)
_startNode = false;
}
if(_startNode)
ds_stack_push(RENDER_STACK, _node);
}
}
2022-01-23 04:08:16 +01:00
renderUpdated();
2022-01-13 05:24:03 +01:00
}
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];
_node.setRenderStatus(false);
if(_in.value_from != noone)
_startNode = false;
}
if(_startNode)
ds_stack_push(_stack, _node);
}
}
}
2022-01-23 04:08:16 +01:00
function renderUpdated() {
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
//show_debug_message("\n=== RENDER ===")
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
if(rendering.rendered) continue;
var txt = "rendering " + rendering.name + " ";
if(LOADING || APPENDING || rendering.auto_update) {
rendering.doUpdate();
txt += "| Updated ";
2022-01-13 05:24:03 +01:00
}
2022-01-24 02:21:25 +01:00
rendering.setRenderStatus(true);
if(instanceof(rendering) == "Node_Group") { //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-13 05:24:03 +01:00
if(_in.isUpdateReady()) ds_stack_push(RENDER_STACK, _in);
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-01-18 05:31:19 +01:00
var _ot = rendering.outParent;
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];
if(_to.node.active && _to.value_from != noone && _to.value_from.node == rendering.group) {
_to.node.setRenderStatus(false);
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
rendering.group.setRenderStatus(true);
} 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;
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;
var _ren = _node_it.outputRendered();
2022-01-24 02:21:25 +01:00
if(_ren == 1) { //Go back to the beginning of the loop, reset render status for leaf node inside?
//show_debug_message("iteration restart");
2022-01-23 04:08:16 +01:00
var _ot = rendering.group.inputs;
for(var j = 1; j < ds_list_size(_ot); j++) {
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
__nodeLeafList(rendering.group.nodes, RENDER_STACK);
2022-01-23 04:08:16 +01:00
} else if(_ren == 2) { //Go out of loop
//show_debug_message("iteration completed");
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-01-23 04:08:16 +01:00
_to.node.setRenderStatus(false);
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
rendering.group.setRenderStatus(true);
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];
if(_to.node.active && _to.value_from != noone && _to.value_from.node == rendering) {
2022-01-23 04:08:16 +01:00
_to.node.setRenderStatus(false);
if(_to.node.isUpdateReady()) ds_stack_push(RENDER_STACK, _to.node);
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
}
}
/*
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-01-23 04:08:16 +01:00
_allnode.setRenderStatus(false);
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
}