Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
material_script.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef MATERIAL_SCRIPT_H
20 #define MATERIAL_SCRIPT_H
21 
22 #include <stdexcept>
23 #include <string>
24 #include <vector>
25 
26 #include "../generic/managed.h"
27 #include "../assets/material.h"
28 #include "../types.h"
29 #include "../loader.h"
30 #include "../path.h"
31 
32 namespace smlt {
33 
34 class SyntaxError : public std::logic_error {
35 public:
36  SyntaxError(const unicode& what):
37  std::logic_error(what.encode()) {}
38 };
39 
41  public RefCounted<MaterialScript> {
42 public:
43  MaterialScript(std::shared_ptr<std::istream> data, const smlt::Path& filename);
44  void generate(Material& material);
45 
46 private:
47  Path filename_;
48  std::shared_ptr<std::istream> data_;
49 };
50 
51 namespace loaders {
52 
53 
55  public Loader {
56 
57 public:
58  MaterialScriptLoader(const Path& filename, std::shared_ptr<std::istream> data):
59  Loader(filename, data) {
60  parser_ = MaterialScript::create(data, filename);
61  }
62 
63  void into(Loadable& resource, const LoaderOptions& options) override;
64 
65 private:
66  MaterialScript::ptr parser_;
67 };
68 
70 public:
71  const char* name() { return "material"; }
72  bool supports(const Path& filename) const {
73  auto e = filename.ext();
74  return e == ".smat";
75  }
76 
77  Loader::ptr loader_for(const Path& filename, std::shared_ptr<std::istream> data) const {
78  return Loader::ptr(new MaterialScriptLoader(filename, data));
79  }
80 };
81 
82 }
83 }
84 
85 #endif // MATERIAL_SCRIPT_H
smlt::loaders::MaterialScriptLoaderType
Definition: material_script.h:69
smlt::Material
Definition: material.h:95
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::LoaderType
Definition: loader.h:111
smlt::Loader
Definition: loader.h:66
smlt::loaders::MaterialScriptLoader
Definition: material_script.h:55
smlt::SyntaxError
Definition: material_script.h:34
smlt::MaterialScript
Definition: material_script.h:41
smlt::Path
Definition: path.h:7
smlt::Loadable
Definition: loadable.h:26
unicode
Definition: unicode.h:36