<commit_before>#include "celib/map.inl"

#include <cetech/modules/debugui/debugui.h>
#include <cetech/modules/playground/asset_property.h>
#include <cetech/kernel/resource.h>
#include <cetech/modules/playground/command_system.h>

#include "cetech/kernel/hashlib.h"
#include "cetech/kernel/config.h"
#include "cetech/kernel/memory.h"
#include "cetech/kernel/api_system.h"
#include "cetech/kernel/module.h"

CETECH_DECL_API(ct_memory_a0);
CETECH_DECL_API(ct_hash_a0);

using namespace celib;

//TODO: MULTIPLE BUFFER (level view has own queue, identify by selected item);

#define _G asset_property_global
static struct _G {
    Map<ct_cmd_execute_t> cmd_map;
    Array<uint8_t> cmd_buffer;
    Array<uint32_t > cmd;
    uint32_t curent_pos;
} _G;


void execute(const struct ct_cmd *cmd) {
    ct_cmd_execute_t cmd_fce = map::get<ct_cmd_execute_t>(_G.cmd_map, cmd->type, NULL);

    if(!cmd_fce) {
        return;
    }

    uint32_t size = array::size(_G.cmd_buffer);


    array::push<uint8_t>(_G.cmd_buffer, (uint8_t*)cmd, cmd->size);
    array::push_back<uint32_t >(_G.cmd, size);

    _G.curent_pos += 1;

    cmd_fce(cmd, false);
}

void register_cmd_execute(uint64_t type, ct_cmd_execute_t execute) {
    map::set(_G.cmd_map, type, execute);
}


static ct_cmd* get_curent_cmd() {
    if (!_G.curent_pos) {
        return NULL;
    }

    ct_cmd* curent_cmd = (ct_cmd*)&_G.cmd_buffer[_G.cmd[_G.curent_pos]];

    return curent_cmd;
}

void undo() {
    ct_cmd* curent_cmd = get_curent_cmd();

    if(!curent_cmd) {
        return;
    }

    ct_cmd_execute_t cmd_fce = map::get<ct_cmd_execute_t>(_G.cmd_map, curent_cmd->type, NULL);

    if(!cmd_fce) {
        return;
    }<commit_msg>PLAYGR-50 - New playground - command_system - cmd after undo<commit_after>#include "celib/map.inl"

#include <cetech/modules/debugui/debugui.h>
#include <cetech/modules/playground/asset_property.h>
#include <cetech/kernel/resource.h>
#include <cetech/modules/playground/command_system.h>

#include "cetech/kernel/hashlib.h"
#include "cetech/kernel/config.h"
#include "cetech/kernel/memory.h"
#include "cetech/kernel/api_system.h"
#include "cetech/kernel/module.h"

CETECH_DECL_API(ct_memory_a0);
CETECH_DECL_API(ct_hash_a0);

using namespace celib;

//TODO: MULTIPLE BUFFER (level view has own queue, identify by selected item);

#define _G asset_property_global
static struct _G {
    Map<ct_cmd_execute_t> cmd_map;
    Array<uint8_t> cmd_buffer;
    Array<uint32_t > cmd;
    uint32_t curent_pos;
} _G;


static ct_cmd* get_curent_cmd() {
    if (!_G.curent_pos) {
        return NULL;
    }

    ct_cmd* curent_cmd = (ct_cmd*)&_G.cmd_buffer[_G.cmd[_G.curent_pos]];

    return curent_cmd;
}

void execute(const struct ct_cmd *cmd) {
    ct_cmd_execute_t cmd_fce = map::get<ct_cmd_execute_t>(_G.cmd_map, cmd->type, NULL);

    if(!cmd_fce) {
        return;
    }

    uint32_t buffer_offset = array::size(_G.cmd_buffer);
    uint32_t size = array::size(_G.cmd);

    if(_G.curent_pos != (size-1)) {
        ct_cmd* cur_cmd = get_curent_cmd();
        if(cur_cmd) {
            uint32_t offset = _G.cmd[_G.curent_pos];
            uint32_t end_offset = offset + cur_cmd->size;

            array::resize(_G.cmd, _G.curent_pos + 1);
            array::resize(_G.cmd_buffer, end_offset);
        }
    }

    array::push<uint8_t>(_G.cmd_buffer, (uint8_t*)cmd, cmd->size);
    array::push_back<uint32_t >(_G.cmd, buffer_offset);

    _G.curent_pos += 1;

    cmd_fce(cmd, false);
}

void register_cmd_execute(uint64_t type, ct_cmd_execute_t execute) {
    map::set(_G.cmd_map, type, execute);
}


void undo() {
    ct_cmd* curent_cmd = get_curent_cmd();

    if(!curent_cmd) {
        return;
    }

    ct_cmd_execute_t cmd_fce = map::get<ct_cmd_execute_t>(_G.cmd_map, curent_cmd->type, NULL);

    if(!cmd_fce) {
        return;
    }
{'fraction_non_alphanumeric': 0.13460533193936225, 'fraction_numerical': 0.01097752221641401, 'mean_word_length': 3.7957393483709274, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3105341', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1536, 'n_words': 249}