Coverage Report

Created: 2025-11-11 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreResourceBackgroundQueue.cpp
Line
Count
Source
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
    (Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org/
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
#include "OgreStableHeaders.h"
29
#include "OgreResourceBackgroundQueue.h"
30
31
namespace Ogre {
32
33
    // Note, no locks are required here anymore because all of the parallelisation
34
    // is now contained in WorkQueue - this class is entirely single-threaded
35
    //------------------------------------------------------------------------
36
    //-----------------------------------------------------------------------
37
    template<> ResourceBackgroundQueue* Singleton<ResourceBackgroundQueue>::msSingleton = 0;
38
    ResourceBackgroundQueue* ResourceBackgroundQueue::getSingletonPtr(void)
39
0
    {
40
0
        return msSingleton;
41
0
    }
42
    ResourceBackgroundQueue& ResourceBackgroundQueue::getSingleton(void)
43
0
    {  
44
0
        assert( msSingleton );  return ( *msSingleton );  
45
0
    }
46
    //------------------------------------------------------------------------
47
1
    ResourceBackgroundQueue::ResourceBackgroundQueue() {}
48
1
    ResourceBackgroundQueue::~ResourceBackgroundQueue() {}
49
    //------------------------------------------------------------------------
50
    std::future<void> ResourceBackgroundQueue::initialiseResourceGroup(const String& name)
51
0
    {
52
0
        auto task = std::make_shared<std::packaged_task<void()>>(
53
0
            [name]() { ResourceGroupManager::getSingleton().initialiseResourceGroup(name); });
54
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
55
0
        return task->get_future();
56
0
    }
57
    //------------------------------------------------------------------------
58
    std::future<void> ResourceBackgroundQueue::initialiseAllResourceGroups()
59
0
    {
60
0
        auto task = std::make_shared<std::packaged_task<void()>>(
61
0
            []() { ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); });
62
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
63
0
        return task->get_future();
64
0
    }
65
    //------------------------------------------------------------------------
66
    std::future<void> ResourceBackgroundQueue::prepareResourceGroup(const String& name)
67
0
    {
68
0
        auto task = std::make_shared<std::packaged_task<void()>>(
69
0
            [name]() { ResourceGroupManager::getSingleton().prepareResourceGroup(name); });
70
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
71
0
        return task->get_future();
72
0
    }
73
    //------------------------------------------------------------------------
74
    std::future<void> ResourceBackgroundQueue::loadResourceGroup(const String& name)
75
0
    {
76
0
        auto task = std::make_shared<std::packaged_task<void()>>([name]()
77
0
        {
78
#   if OGRE_THREAD_SUPPORT == 1
79
            ResourceGroupManager::getSingleton().loadResourceGroup(name);
80
#   else
81
0
            ResourceGroupManager::getSingleton().prepareResourceGroup(name);
82
0
            Root::getSingleton().getWorkQueue()->addMainThreadTask(
83
0
                [name]() { ResourceGroupManager::getSingleton().loadResourceGroup(name); });
84
0
#   endif
85
0
        });
86
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
87
0
        return task->get_future();
88
0
    }
89
    //------------------------------------------------------------------------
90
    std::future<void> ResourceBackgroundQueue::prepare(const ResourcePtr& res)
91
0
    {
92
0
        auto task = std::make_shared<std::packaged_task<void()>>(
93
0
            [res]()
94
0
            {
95
0
                res->prepare(true);
96
0
                Root::getSingleton().getWorkQueue()->addMainThreadTask([res]() { res->_firePreparingComplete(); });
97
0
            });
98
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
99
0
        return task->get_future();
100
0
    }
101
    //------------------------------------------------------------------------
102
    std::future<void> ResourceBackgroundQueue::load(const ResourcePtr& res)
103
0
    {
104
0
        auto task = std::make_shared<std::packaged_task<void()>>(
105
0
            [res]()
106
0
            {
107
#if OGRE_THREAD_SUPPORT == 1
108
                res->load(true);
109
                Root::getSingleton().getWorkQueue()->addMainThreadTask([res]() { res->_fireLoadingComplete(); });
110
#else
111
0
                res->prepare(true);
112
0
                Root::getSingleton().getWorkQueue()->addMainThreadTask(
113
0
                    [res]()
114
0
                    {
115
0
                        res->load(true);
116
0
                        res->_fireLoadingComplete();
117
0
                    });
118
0
#endif
119
0
            });
120
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
121
0
        return task->get_future();
122
0
    }
123
    //---------------------------------------------------------------------
124
    std::future<void> ResourceBackgroundQueue::unload(const ResourcePtr& res)
125
0
    {
126
0
        auto task = std::make_shared<std::packaged_task<void()>>([res]() { res->unload(); });
127
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
128
0
        return task->get_future();
129
0
    }
130
    //---------------------------------------------------------------------
131
    std::future<void> ResourceBackgroundQueue::unloadResourceGroup(const String& name)
132
0
    {
133
0
        auto task = std::make_shared<std::packaged_task<void()>>(
134
0
            [name]() { ResourceGroupManager::getSingleton().unloadResourceGroup(name); });
135
0
        Root::getSingleton().getWorkQueue()->addTask([task]() { (*task)(); });
136
0
        return task->get_future();
137
0
    }
138
139
}
140
141
142