v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
metadata.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * Sifteo SDK
4  *
5  * Copyright <c> 2012 Sifteo, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #pragma once
27 #ifdef NOT_USERSPACE
28 # error This is a userspace-only header, not allowed by the current build.
29 #endif
30 
31 #include <sifteo/abi.h>
32 
33 namespace Sifteo {
34 
71 class Metadata {
72 public:
80  {
81  // Metadata that's automatically inserted only once
82  if (_SYS_lti_counter("Sifteo.Metadata", 0) == 0) {
83 
84  // Count the total number of AssetGroupSlots in use
85  unsigned numAGSlots = _SYS_lti_counter("Sifteo.AssetGroupSlot", -1);
86  _SYS_lti_metadata(_SYS_METADATA_NUM_ASLOTS, "b", numAGSlots);
87 
88  // UUID for this particular build.
89  _SYS_lti_metadata(_SYS_METADATA_UUID, "IIII",
90  _SYS_lti_uuid(0, 0), _SYS_lti_uuid(0, 1),
91  _SYS_lti_uuid(0, 2), _SYS_lti_uuid(0, 3));
92  }
93  }
94 
98  Metadata &title(const char *str)
99  {
100  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Title", 0) != 0,
101  "Duplicate Metadata::title() instance.");
102 
103  _SYS_lti_metadata(_SYS_METADATA_TITLE_STR, "sB", str, 0);
104 
105  return *this;
106  }
107 
119  Metadata &package(const char *pkg, const char *version)
120  {
121  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Package", 0) != 0,
122  "Duplicate Metadata::package() instance.");
123 
124  _SYS_lti_metadata(_SYS_METADATA_PACKAGE_STR, "sB", pkg, 0);
125  _SYS_lti_metadata(_SYS_METADATA_VERSION_STR, "sB", version, 0);
126 
127  return *this;
128  }
129 
140  Metadata &isDemoOf(const char *fullAppPkgID)
141  {
142  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.IsDemoOf", 0) != 0,
143  "Duplicate Metadata::isDemoOf() instance.");
144 
145  _SYS_lti_metadata(_SYS_METADATA_IS_DEMO_OF_STR, "sB", fullAppPkgID, 0);
146 
147  return *this;
148  }
149 
156  Metadata &icon(const _SYSAssetImage &i)
157  {
158  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Icon", 0) != 0,
159  "Duplicate Metadata::icon() instance.");
160  _SYS_lti_abort(i.width != 96/8 || i.height != 96/8,
161  "Metadata::icon() image must be 96x96 pixels in size.");
162 
163  return image(_SYS_METADATA_ICON_96x96, i);
164  }
165 
170  Metadata &image(uint16_t key, const _SYSAssetImage &i)
171  {
172  // AssetGroup is in RAM, but we want the static initializer data
173  _SYSAssetGroup *G = (_SYSAssetGroup*) _SYS_lti_initializer(
174  reinterpret_cast<const void*>(i.pAssetGroup), true);
175 
176  // Build a _SYSMetadataImage struct
177  _SYS_lti_metadata(key, "BBBBII",
178  i.width, i.height, i.frames, i.format, G->pHdr, i.pData);
179 
180  return *this;
181  }
182 
189  Metadata &cubeRange(unsigned minCubes, unsigned maxCubes)
190  {
191  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.CubeRange", 0) != 0,
192  "Duplicate Metadata::cubeRange() instance.");
193  _SYS_lti_abort(minCubes > _SYS_NUM_CUBE_SLOTS,
194  "Minimum number of cubes is too high.");
195  _SYS_lti_abort(maxCubes > _SYS_NUM_CUBE_SLOTS,
196  "Maximum number of cubes is too high.");
197  _SYS_lti_abort(minCubes > maxCubes,
198  "Minimum number of cubes must be <= maximum number");
199 
200  _SYS_lti_metadata(_SYS_METADATA_CUBE_RANGE, "BB", minCubes, maxCubes);
201 
202  return *this;
203  }
204 
214  Metadata &cubeRange(unsigned count)
215  {
216  return cubeRange(count, count);
217  }
218 
228  Metadata &minimumOSVersion(uint32_t version)
229  {
230  _SYS_lti_abort((version & 0xff000000) != 0,
231  "Metadata::minimumOSVersion(): invalid version. Must be of the form "
232  "0xMMNNPP (MM = major, NN = minor, PP = patch).");
233 
234  _SYS_lti_metadata(_SYS_METADATA_MIN_OS_VERSION, "I", version);
235  return *this;
236  }
237 };
238 
243 } // namespace Sifteo
Metadata()
Initialize all required system metadata.
Definition: metadata.h:79
Metadata & cubeRange(unsigned minCubes, unsigned maxCubes)
Set the minimum and maximum number of supported cubes for this game.
Definition: metadata.h:189
Metadata & isDemoOf(const char *fullAppPkgID)
Indicate that this app is a demo, providing the package ID of the "full" version of this app...
Definition: metadata.h:140
Metadata & cubeRange(unsigned count)
The one-argument version of cubeRange sets up identical minimum and maximum cube counts.
Definition: metadata.h:214
Metadata & minimumOSVersion(uint32_t version)
Specify the minimum OS version required to run your application.
Definition: metadata.h:228
Metadata & title(const char *str)
Add a human-readable title string to this game's metadata.
Definition: metadata.h:98
Metadata & package(const char *pkg, const char *version)
Add a unique machine-readable identity string to this game's metadata.
Definition: metadata.h:119
Definition: array.h:34
Metadata & image(uint16_t key, const _SYSAssetImage &i)
Add an arbitrary image, as a _SYSMetadataImage item, with a user-specified key.
Definition: metadata.h:170
Metadata & icon(const _SYSAssetImage &i)
Add an icon image to this game's metadata.
Definition: metadata.h:156
Metadata objects are special compile-time mechanisms for annotating your game's ELF binary with addit...
Definition: metadata.h:71