Pixel-Composer/scripts/render_data/render_data.gml

101 lines
2.6 KiB
Plaintext
Raw Normal View History

enum RENDER_TYPE {
none = 0,
partial = 1,
full = 2
}
2023-02-19 13:49:20 +01:00
global.RENDER_LOG = false;
2023-02-19 02:13:19 +01:00
global.group_inputs = [ "Node_Group_Input", "Node_Feedback_Input", "Node_Iterator_Input", "Node_Iterator_Each_Input" ];
2022-12-13 09:20:36 +01:00
2023-01-25 06:49:00 +01:00
function __nodeLeafList(_list, _queue) {
2022-01-24 02:21:25 +01:00
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;
2023-02-19 13:49:20 +01:00
if(!_node.renderActive) continue;
2022-12-13 09:20:36 +01:00
2022-12-18 03:20:38 +01:00
var _startNode = _node.isRenderable(true);
2022-12-13 09:20:36 +01:00
if(_startNode) {
2023-01-25 06:49:00 +01:00
ds_queue_enqueue(_queue, _node);
2022-12-13 09:20:36 +01:00
printIf(global.RENDER_LOG, "Push node " + _node.name + " to stack");
2022-01-24 02:21:25 +01:00
}
}
}
2023-02-14 11:40:24 +01:00
function __nodeIsLoop(_node) {
switch(instanceof(_node)) {
case "Node_Iterate" :
case "Node_Iterate_Each" :
case "Node_Feedback" :
return true;
}
return false;
}
2022-12-16 09:18:09 +01:00
function __nodeInLoop(_node) {
var gr = _node.group;
while(gr != -1) {
2023-02-14 11:40:24 +01:00
if(__nodeIsLoop(gr)) return true;
2022-12-16 09:18:09 +01:00
gr = gr.group;
}
return false;
}
2022-12-10 05:06:01 +01:00
function Render(partial = false) {
2023-02-14 02:51:14 +01:00
try {
var rendering = noone;
var error = 0;
var t = current_time;
printIf(global.RENDER_LOG, "=== RENDER START [frame " + string(ANIMATOR.current_frame) + "] ===");
if(!partial || ALWAYS_FULL) {
var _key = ds_map_find_first(NODE_MAP);
var amo = ds_map_size(NODE_MAP);
2022-12-16 09:18:09 +01:00
2023-02-14 02:51:14 +01:00
repeat(amo) {
var _node = NODE_MAP[? _key];
_node.setRenderStatus(false);
_key = ds_map_find_next(NODE_MAP, _key);
}
2022-12-10 05:06:01 +01:00
}
2023-02-14 02:51:14 +01:00
// get leaf node
ds_queue_clear(RENDER_QUEUE);
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);
2022-12-10 05:06:01 +01:00
2023-02-14 02:51:14 +01:00
if(is_undefined(_node)) continue;
if(!is_struct(_node)) continue;
2023-02-14 11:40:24 +01:00
if(array_exists(global.group_inputs, instanceof(_node))) continue;
2022-12-10 05:06:01 +01:00
2023-02-14 02:51:14 +01:00
if(!_node.active) continue;
2023-02-19 13:49:20 +01:00
if(!_node.renderActive) continue;
2023-02-14 02:51:14 +01:00
if(_node.rendered) continue;
if(__nodeInLoop(_node)) continue;
2022-12-13 09:20:36 +01:00
2023-02-14 02:51:14 +01:00
var _startNode = _node.isRenderable();
if(_startNode) {
ds_queue_enqueue(RENDER_QUEUE, _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
2023-02-14 02:51:14 +01:00
// render forward
while(!ds_queue_empty(RENDER_QUEUE)) {
rendering = ds_queue_dequeue(RENDER_QUEUE);
2022-01-24 02:21:25 +01:00
2023-02-14 02:51:14 +01:00
var txt = rendering.rendered? " [Skip]" : " [Update]";
if(!rendering.rendered) {
rendering.doUpdate();
rendering.setRenderStatus(true);
2023-02-19 02:13:19 +01:00
rendering.getNextNodes();
2023-02-14 02:51:14 +01:00
}
printIf(global.RENDER_LOG, "Rendered " + rendering.name + " [" + string(instanceof(rendering)) + "]" + txt);
2022-01-13 05:24:03 +01:00
}
2022-12-12 09:08:03 +01:00
2023-02-14 02:51:14 +01:00
printIf(global.RENDER_LOG, "=== RENDER COMPLETE IN {" + string(current_time - t) + "ms} ===\n");
} catch(e)
2023-02-19 02:13:19 +01:00
noti_warning(exception_print(e));
2022-01-13 05:24:03 +01:00
}