xoreos  0.0.5
util.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <cstdarg>
26 
27 #include <vector>
28 
29 #include "src/common/scopedptr.h"
30 #include "src/common/ptrvector.h"
31 #include "src/common/error.h"
32 #include "src/common/ustring.h"
33 #include "src/common/readstream.h"
34 
35 #include "src/aurora/resman.h"
36 
38 
43 
44 #include "src/engines/sonic/util.h"
45 
46 namespace Engines {
47 
48 namespace Sonic {
49 
51  uint32 width, uint32 height, ...) {
52 
53  Graphics::Aurora::TextureHandle handle = TextureMan.getIfExist(name);
54  if (!handle.empty())
55  return handle;
56 
58  if (!nclrStream)
59  throw Common::Exception("No such NCLR \"%s\"", nclr.c_str());
60 
62  ncgrs.resize(width * height, 0);
63 
64  va_list va;
65  va_start(va, height);
66 
67  for (uint32 i = 0; i < width * height; i++) {
68  const char *str = va_arg(va, const char *);
69  if (!str)
70  continue;
71 
72  ncgrs[i] = ResMan.getResource(name + Common::UString(str), ::Aurora::kFileTypeNCGR);
73  if (!ncgrs[i])
74  throw Common::Exception("No such NCGR \"%s\"", (name + Common::UString(str)).c_str());
75  }
76 
77  va_end(va);
78 
79  Common::ScopedPtr<Graphics::NCGR> image(new Graphics::NCGR(ncgrs, width, height, *nclrStream));
80 
82  image.release();
83 
84  return TextureMan.add(texture, name);
85 }
86 
87 Graphics::Aurora::FontHandle loadFont(const Common::UString &name, const Common::UString &nftr, bool invert) {
88  Graphics::Aurora::FontHandle handle = FontMan.getIfExist(name);
89  if (!handle.empty())
90  return handle;
91 
92  handle = FontMan.add(new Graphics::Aurora::NFTRFont(nftr, invert), name);
93  return handle;
94 }
95 
96 } // End of namespace Sonic
97 
98 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Graphics::Aurora::TextureHandle loadNCGR(const Common::UString &name, const Common::UString &nclr, uint32 width, uint32 height,...)
Definition: util.cpp:50
A class holding an UTF-8 string.
Definition: ustring.h:48
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
Definition: scopedptr.h:103
Graphics::Aurora::FontHandle loadFont(const Common::UString &name, const Common::UString &nftr, bool invert)
Definition: util.cpp:87
static Texture * create(const Common::UString &name, bool deswizzle=false)
Create a texture from this image resource.
Definition: texture.cpp:323
The Aurora texture manager.
A handle to a font.
Definition: fonthandle.h:52
void resize(typename std::vector< T *>::size_type n, typename std::vector< T *>::value_type val=typename std::vector< T *>::value_type())
Definition: ptrvector.h:76
The Aurora font manager.
Image decoder for Nintendo&#39;s tile-based graphics format.
Definition: ncgr.h:58
A simple scoped smart pointer template.
Palette, Nitro CoLoR.
Definition: types.h:267
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Nintendo&#39;s NFTR font, found in Sonic.
StackException Exception
Definition: error.h:59
A vector storing pointer to objects, with automatic deletion.
Basic reading stream interfaces.
Unicode string handling.
Sonic Chronicles: The Dark Brotherhood utility functions.
PointerType get() const
Returns the plain pointer value.
Definition: scopedptr.h:96
A texture as used in the Aurora engines.
uint32_t uint32
Definition: types.h:204
Image, Nitro Character Graphic Resource.
Definition: types.h:266
Nitro Character Graphic Resource, a Nintendo DS image format.
A handle to a texture.
Definition: texturehandle.h:51
The global resource manager for Aurora resources.
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105