Pixel-Composer/scripts/render_data/render_data.gml

202 lines
5.5 KiB
Plaintext
Raw Normal View History

enum RENDER_TYPE {
none = 0,
partial = 1,
full = 2
}
2023-03-28 06:58:28 +02:00
#region globalvar
global.RENDER_DEBUG = false;
global.RENDER_LOG = false;
global.group_inputs = [ "Node_Group_Input", "Node_Feedback_Input", "Node_Iterator_Input", "Node_Iterator_Each_Input" ];
#endregion
2022-12-13 09:20:36 +01:00
2023-03-28 06:58:28 +02:00
function __nodeLeafList(_list) {
var nodes = [];
LOG_BLOCK_START();
2023-03-28 06:58:28 +02:00
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
2023-03-26 07:13:36 +02:00
var _startNode = _node.isRenderable();
2022-12-13 09:20:36 +01:00
if(_startNode) {
2023-03-28 06:58:28 +02:00
array_push(nodes, _node);
LOG_IF(global.RENDER_LOG, "Push node " + _node.name + " to stack");
2022-01-24 02:21:25 +01:00
}
}
2023-03-28 06:58:28 +02:00
LOG_BLOCK_END();
2023-03-28 06:58:28 +02:00
return nodes;
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" :
2023-03-24 05:55:34 +01:00
case "Node_Iterate_Filter" :
case "Node_Feedback" :
2023-02-14 11:40:24 +01:00
return true;
}
return false;
}
2022-12-16 09:18:09 +01:00
function __nodeInLoop(_node) {
var gr = _node.group;
2023-02-28 09:43:01 +01:00
while(gr != noone) {
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;
}
2023-03-02 07:59:14 +01:00
function Render(partial = false, runAction = false) {
2023-03-28 06:58:28 +02:00
var t = current_time;
LOG_BLOCK_START();
LOG_IF(global.RENDER_LOG, "=== RENDER START [frame " + string(ANIMATOR.current_frame) + "] ===");
2023-03-28 06:58:28 +02:00
2023-02-14 02:51:14 +01:00
try {
var rendering = noone;
var error = 0;
2023-03-28 06:58:28 +02:00
2023-02-14 02:51:14 +01:00
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;
2023-03-26 07:13:36 +02:00
if(!is_struct(_node)) continue;
2023-02-14 11:40:24 +01:00
if(array_exists(global.group_inputs, instanceof(_node))) continue;
2023-03-26 07:13:36 +02:00
if(!_node.active) continue;
2023-02-19 13:49:20 +01:00
if(!_node.renderActive) continue;
2023-03-29 15:02:03 +02:00
if(_node.rendered) {
LOG_IF(global.RENDER_LOG, "Skip rendered " + _node.name + " (" + _node.display_name + ")");
2023-03-29 15:02:03 +02:00
continue;
}
2023-02-14 02:51:14 +01:00
if(__nodeInLoop(_node)) continue;
2023-03-29 15:02:03 +02:00
LOG_BLOCK_START();
2023-03-29 15:02:03 +02:00
var _startNode = _node.isRenderable(global.RENDER_LOG);
2023-03-28 06:58:28 +02:00
if(_startNode) {
LOG_IF(global.RENDER_LOG, "Found leaf " + _node.name + " (" + _node.display_name + ")");
2023-03-28 06:58:28 +02:00
_node.triggerRender();
2023-02-14 02:51:14 +01:00
ds_queue_enqueue(RENDER_QUEUE, _node);
2023-03-29 15:02:03 +02:00
} else
LOG_IF(global.RENDER_LOG, "Skip non-leaf " + _node.name + " (" + _node.display_name + ")");
LOG_BLOCK_END();
2022-12-10 05:06:01 +01:00
}
LOG_IF(global.RENDER_LOG, "Get leaf complete: found " + string(ds_queue_size(RENDER_QUEUE)) + " leaves.");
LOG_IF(global.RENDER_LOG, "Start rendering...");
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);
2023-04-04 13:44:37 +02:00
var renderable = rendering.isRenderable();
LOG_BLOCK_START();
2023-04-04 13:44:37 +02:00
LOG_IF(global.RENDER_LOG, "Rendering " + rendering.name + " (" + rendering.display_name + ") ");
2023-03-29 15:02:03 +02:00
2023-04-04 13:44:37 +02:00
if(renderable) {
2023-03-02 07:59:14 +01:00
rendering.doUpdate();
2023-03-28 06:58:28 +02:00
var nextNodes = rendering.getNextNodes();
2023-03-29 15:02:03 +02:00
for( var i = 0; i < array_length(nextNodes); i++ )
2023-03-28 06:58:28 +02:00
ds_queue_enqueue(RENDER_QUEUE, nextNodes[i]);
2023-03-02 07:59:14 +01:00
2023-03-28 06:58:28 +02:00
if(runAction && rendering.hasInspector1Update())
rendering.inspector1Update();
2023-03-29 15:02:03 +02:00
}
2023-04-04 13:44:37 +02:00
LOG_IF(global.RENDER_LOG, "Rendered " + rendering.name + " (" + rendering.display_name + ") [" + string(instanceof(rendering)) + "]" + (renderable? " [Update]" : " [Skip]"));
LOG_BLOCK_END();
2023-03-02 07:59:14 +01:00
}
} catch(e)
noti_warning(exception_print(e));
2023-03-28 06:58:28 +02:00
LOG_IF(global.RENDER_LOG, "=== RENDER COMPLETE IN {" + string(current_time - t) + "ms} ===\n");
LOG_END();
2023-03-02 07:59:14 +01:00
}
function __renderListReset(list) {
for( var i = 0; i < ds_list_size(list); i++ ) {
list[| i].setRenderStatus(false);
2023-03-24 05:55:34 +01:00
2023-03-02 07:59:14 +01:00
if(struct_has(list[| i], "nodes"))
__renderListReset(list[| i].nodes);
}
}
function RenderListAction(list, context = PANEL_GRAPH.getCurrentContext()) {
2023-03-24 05:55:34 +01:00
printIf(global.RENDER_LOG, "=== RENDER LIST ACTION START [frame " + string(ANIMATOR.current_frame) + "] ===");
2023-03-02 07:59:14 +01:00
try {
var rendering = noone;
2023-03-24 05:55:34 +01:00
var error = 0;
var t = current_time;
2023-03-02 07:59:14 +01:00
__renderListReset(list);
// get leaf node
ds_queue_clear(RENDER_QUEUE);
for( var i = 0; i < ds_list_size(list); i++ ) {
var _node = list[| i];
if(is_undefined(_node)) continue;
2023-03-24 05:55:34 +01:00
if(!is_struct(_node)) continue;
2023-03-02 07:59:14 +01:00
2023-03-24 05:55:34 +01:00
if(!_node.active) continue;
2023-03-02 07:59:14 +01:00
if(!_node.renderActive) continue;
2023-03-24 05:55:34 +01:00
if(_node.rendered) continue;
2023-03-02 07:59:14 +01:00
2023-03-24 05:55:34 +01:00
if(_node.isRenderable()) {
2023-03-02 07:59:14 +01:00
ds_queue_enqueue(RENDER_QUEUE, _node);
2023-03-29 15:02:03 +02:00
printIf(global.RENDER_LOG, " > Push " + _node.name + " (" + _node.display_name + ") node to stack");
2023-03-02 07:59:14 +01:00
}
}
// render forward
while(!ds_queue_empty(RENDER_QUEUE)) {
rendering = ds_queue_dequeue(RENDER_QUEUE);
if(rendering.group == context) break;
2023-04-04 09:49:33 +02:00
var txt = rendering.isRenderable()? " [Skip]" : " [Update]";
2023-03-29 15:02:03 +02:00
2023-04-04 09:49:33 +02:00
if(!rendering.isRenderable()) {
2023-02-14 02:51:14 +01:00
rendering.doUpdate();
2023-03-28 06:58:28 +02:00
if(rendering.hasInspector1Update()) {
rendering.inspector1Update();
2023-03-24 05:55:34 +01:00
printIf(global.RENDER_LOG, " > Toggle manual execution " + rendering.name + " (" + rendering.display_name + ")");
}
2023-03-28 06:58:28 +02:00
var nextNodes = rendering.getNextNodes();
2023-03-29 15:02:03 +02:00
for( var i = 0; i < array_length(nextNodes); i++ )
2023-03-28 06:58:28 +02:00
ds_queue_enqueue(RENDER_QUEUE, nextNodes[i]);
2023-02-14 02:51:14 +01:00
}
2023-03-29 15:02:03 +02:00
2023-03-02 07:59:14 +01:00
printIf(global.RENDER_LOG, "Rendered " + rendering.name + " (" + rendering.display_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
}