v1.1.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 
52 class Metadata {
53 public:
61  {
62  // Metadata that's automatically inserted only once
63  if (_SYS_lti_counter("Sifteo.Metadata", 0) == 0) {
64 
65  // Count the total number of AssetGroupSlots in use
66  unsigned numAGSlots = _SYS_lti_counter("Sifteo.AssetGroupSlot", -1);
67  _SYS_lti_metadata(_SYS_METADATA_NUM_ASLOTS, "b", numAGSlots);
68 
69  // UUID for this particular build.
70  _SYS_lti_metadata(_SYS_METADATA_UUID, "IIII",
71  _SYS_lti_uuid(0, 0), _SYS_lti_uuid(0, 1),
72  _SYS_lti_uuid(0, 2), _SYS_lti_uuid(0, 3));
73  }
74  }
75 
79  Metadata &title(const char *str)
80  {
81  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Title", 0) != 0,
82  "Duplicate Metadata::title() instance.");
83 
84  _SYS_lti_metadata(_SYS_METADATA_TITLE_STR, "sB", str, 0);
85 
86  return *this;
87  }
88 
100  Metadata &package(const char *pkg, const char *version)
101  {
102  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Package", 0) != 0,
103  "Duplicate Metadata::package() instance.");
104 
105  _SYS_lti_metadata(_SYS_METADATA_PACKAGE_STR, "sB", pkg, 0);
106  _SYS_lti_metadata(_SYS_METADATA_VERSION_STR, "sB", version, 0);
107 
108  return *this;
109  }
110 
121  Metadata &isDemoOf(const char *fullAppPkgID)
122  {
123  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.IsDemoOf", 0) != 0,
124  "Duplicate Metadata::isDemoOf() instance.");
125 
126  _SYS_lti_metadata(_SYS_METADATA_IS_DEMO_OF_STR, "sB", fullAppPkgID, 0);
127 
128  return *this;
129  }
130 
137  Metadata &icon(const _SYSAssetImage &i)
138  {
139  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.Icon", 0) != 0,
140  "Duplicate Metadata::icon() instance.");
141  _SYS_lti_abort(i.width != 96/8 || i.height != 96/8,
142  "Metadata::icon() image must be 96x96 pixels in size.");
143 
144  return image(_SYS_METADATA_ICON_96x96, i);
145  }
146 
151  Metadata &image(uint16_t key, const _SYSAssetImage &i)
152  {
153  // AssetGroup is in RAM, but we want the static initializer data
154  _SYSAssetGroup *G = (_SYSAssetGroup*) _SYS_lti_initializer(
155  reinterpret_cast<const void*>(i.pAssetGroup), true);
156 
157  // Build a _SYSMetadataImage struct
158  _SYS_lti_metadata(key, "BBBBII",
159  i.width, i.height, i.frames, i.format, G->pHdr, i.pData);
160 
161  return *this;
162  }
163 
170  Metadata &cubeRange(unsigned minCubes, unsigned maxCubes)
171  {
172  _SYS_lti_abort(_SYS_lti_counter("Sifteo.Metadata.CubeRange", 0) != 0,
173  "Duplicate Metadata::cubeRange() instance.");
174  _SYS_lti_abort(minCubes > _SYS_NUM_CUBE_SLOTS,
175  "Minimum number of cubes is too high.");
176  _SYS_lti_abort(maxCubes > _SYS_NUM_CUBE_SLOTS,
177  "Maximum number of cubes is too high.");
178  _SYS_lti_abort(minCubes > maxCubes,
179  "Minimum number of cubes must be <= maximum number");
180 
181  _SYS_lti_metadata(_SYS_METADATA_CUBE_RANGE, "BB", minCubes, maxCubes);
182 
183  return *this;
184  }
185 
195  Metadata &cubeRange(unsigned count)
196  {
197  return cubeRange(count, count);
198  }
199 
209  Metadata &minimumOSVersion(uint32_t version)
210  {
211  _SYS_lti_abort((version & 0xff000000) != 0,
212  "Metadata::minimumOSVersion(): invalid version. Must be of the form "
213  "0xMMNNPP (MM = major, NN = minor, PP = patch).");
214 
215  _SYS_lti_metadata(_SYS_METADATA_MIN_OS_VERSION, "I", version);
216  return *this;
217  }
218 };
219 
224 } // namespace Sifteo