v1.0.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
metadata.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * This file is part of the public interface to the Sifteo SDK.
4  * Copyright <c> 2012 Sifteo, Inc. All rights reserved.
5  */
6 
7 #pragma once
8 #ifdef NOT_USERSPACE
9 # error This is a userspace-only header, not allowed by the current build.
10 #endif
11 
12 #include <sifteo/abi.h>
13 
14 namespace Sifteo {
15 
46 class Metadata {
47 public:
55  {
56  // Metadata that's automatically inserted only once
57  if (_SYS_lti_counter("Sifteo.Metadata", 0) == 0) {
58 
59  // Count the total number of AssetGroupSlots in use
60  unsigned numAGSlots = _SYS_lti_counter("Sifteo.AssetGroupSlot", -1);
61  _SYS_lti_metadata(_SYS_METADATA_NUM_ASLOTS, "b", numAGSlots);
62 
63  // UUID for this particular build.
64  _SYS_lti_metadata(_SYS_METADATA_UUID, "IIII",
65  _SYS_lti_uuid(0, 0), _SYS_lti_uuid(0, 1),
66  _SYS_lti_uuid(0, 2), _SYS_lti_uuid(0, 3));
67  }
68  }
69 
73  Metadata &title(const char *str)
74  {
75  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Title", 0) != 0,
76  "Duplicate Metadata::title() instance.");
77 
78  _SYS_lti_metadata(_SYS_METADATA_TITLE_STR, "sB", str, 0);
79 
80  return *this;
81  }
82 
94  Metadata &package(const char *pkg, const char *version)
95  {
96  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Package", 0) != 0,
97  "Duplicate Metadata::package() instance.");
98 
99  _SYS_lti_metadata(_SYS_METADATA_PACKAGE_STR, "sB", pkg, 0);
100  _SYS_lti_metadata(_SYS_METADATA_VERSION_STR, "sB", version, 0);
101 
102  return *this;
103  }
104 
111  Metadata &icon(const _SYSAssetImage &i)
112  {
113  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Icon", 0) != 0,
114  "Duplicate Metadata::icon() instance.");
115  _SYS_lti_abort(i.width != 96/8 || i.height != 96/8,
116  "Metadata::icon() image must be 96x96 pixels in size.");
117 
118  return image(_SYS_METADATA_ICON_96x96, i);
119  }
120 
125  Metadata &image(uint16_t key, const _SYSAssetImage &i)
126  {
127  // AssetGroup is in RAM, but we want the static initializer data
128  _SYSAssetGroup *G = (_SYSAssetGroup*) _SYS_lti_initializer(
129  reinterpret_cast<const void*>(i.pAssetGroup), true);
130 
131  // Build a _SYSMetadataImage struct
132  _SYS_lti_metadata(key, "BBBBII",
133  i.width, i.height, i.frames, i.format, G->pHdr, i.pData);
134 
135  return *this;
136  }
137 
144  Metadata &cubeRange(unsigned minCubes, unsigned maxCubes)
145  {
146  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.CubeRange", 0) != 0,
147  "Duplicate Metadata::cubeRange() instance.");
148  _SYS_lti_abort(minCubes > _SYS_NUM_CUBE_SLOTS,
149  "Minimum number of cubes is too high.");
150  _SYS_lti_abort(maxCubes > _SYS_NUM_CUBE_SLOTS,
151  "Maximum number of cubes is too high.");
152  _SYS_lti_abort(minCubes > maxCubes,
153  "Minimum number of cubes must be <= maximum number");
154 
155  _SYS_lti_metadata(_SYS_METADATA_CUBE_RANGE, "BB", minCubes, maxCubes);
156 
157  return *this;
158  }
159 
169  Metadata &cubeRange(unsigned count)
170  {
171  return cubeRange(count, count);
172  }
173 
183  Metadata &minimumOSVersion(uint32_t version)
184  {
185  _SYS_lti_abort((version & 0xff000000) != 0,
186  "Metadata::minimumOSVersion(): invalid version. Must be of the form "
187  "0xMMNNPP (MM = major, NN = minor, PP = patch).");
188 
189  _SYS_lti_metadata(_SYS_METADATA_MIN_OS_VERSION, "I", version);
190  return *this;
191  }
192 };
193 
198 } // namespace Sifteo