Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
assetloader.hpp
1 //////////////////////////////
2 //
3 // File: lxs/system/assetloader.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Nov 27 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_JPEGTEXTURELOADER_
15 #define __LXS_JPEGTEXTURELOADER_
16 #include <utility>
17 #include <unistd.h>
18 namespace LxS
19 {
20  namespace CoreGraphics
21  {
22  class TextureSet;
23  }
24  namespace System
25  {
26  //! class grouping methods for accessing textures and application assets. This is very much OS-specific
28  {
29  friend class ::LxS::CoreGraphics::TextureSet;
30  public:
31  //std::pair<void*, std::pair<color_mode,width> >
32  struct Texture
33  {
34  //! pixels (decompressed)
35  void * data;
36  //! width=height
37  int width;
38  //! width=height
39  int height;
40  //! amount of color channels
42  Texture(): data(0){}
43  //! constructor with initializer
45  void * _data,
46  int _width,
47  int _height,
48  int _color_mode)
49  :data(_data),
50  width(_width),
51  height(_height),
52  color_mode(_color_mode){}
53 
54  };
55  // end of struct texture
56 
57  // return pointer to asset; set size;
58  private:
59  //! Loading JPEG image (this includes texture-decompression and is a highly CPU-consuming process (as well as IO consuming in case of slower data devices))
60  static Texture LoadImageJPEG(const char* FileName, unsigned long * width, int * channels);
61  public:
62  //! Loads an asset as set of characters
63  static char * LoadAsset(const char * name, off_t * size);
64  //! "scan" part of asset. works as scanf with exception, that parameter a is pointer "where to read" returned is position of progressed pointer ("where reading was finished" - typically after newline or at \0)
65  static const char * Scanf(const char * a,const char * fmt,...);
66  //! "gets" part of asset. works as fgets with exception, that parameter a is pointer "where to read" returned is position of progressed pointer ("where reading was finished" - typically after newline or at \0)
67  static char * Fgets(char * s, int size, char * a);
68  //! path must be prefixed
69  //! FILE: - local data in local data directory (dotdir)
70  //! NET: networked repository
71  static void StoreAsset(const char * path, off_t size, const char * buffer);
72  //! just like LoadAsset but handles pathname prefixes
73  //! FILE: - local data in local data directory (dotdir)
74  //! NET: networked repository
75  //! no prefix: asset directory
76  static char * LoadAssetExt(const char * name, off_t * size);
77  };
78  }
79 }
80 #endif