<commit_before>//https://code.google.com/p/nya-engine/

#pragma once

#include "resources/shared_resources.h"
#include "memory/tmp_buffer.h"

namespace nya_scene
{

typedef nya_memory::tmp_buffer_ref resource_data;

template<typename t>
class scene_shared
{
public:
    virtual bool load(const char *name)
    {
        unload();

        if(!name)
            return false;

        if(get_resources_prefix().empty())
            m_shared=get_shared_resources().access(name);
        else
            m_shared=get_shared_resources().access((get_resources_prefix()+name).c_str());

        return m_shared.is_valid();
    }

    void create(const t &res)
    {
        typename shared_resources::shared_resource_mutable_ref ref=get_shared_resources().create();
        if(!ref.is_valid())
        {
            unload();
            return;
        }
<commit_msg>scene: do not unload-load resource with the same name<commit_after>//https://code.google.com/p/nya-engine/

#pragma once

#include "resources/shared_resources.h"
#include "memory/tmp_buffer.h"

namespace nya_scene
{

typedef nya_memory::tmp_buffer_ref resource_data;

template<typename t>
class scene_shared
{
public:
    virtual bool load(const char *name)
    {
        if(!name)
        {
            unload();
            return false;
        }

        const std::string final_name=get_resources_prefix()+name;
        if(m_shared.is_valid())
        {
            const char *res_name=m_shared.get_name();
            if(res_name && final_name==res_name)
                return true;
        }

        unload();

        m_shared=get_shared_resources().access(final_name.c_str());

        return m_shared.is_valid();
    }

    void create(const t &res)
    {
        typename shared_resources::shared_resource_mutable_ref ref=get_shared_resources().create();
        if(!ref.is_valid())
        {
            unload();
            return;
        }

{'fraction_non_alphanumeric': 0.1149843912591051, 'fraction_numerical': 0.0, 'mean_word_length': 2.464864864864865, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5291190', 'n_tokens_mistral': 603, 'n_tokens_neox': 586, 'n_words': 101}