1 /**
2 Copyright (c) 2018 Clipsey (clipseypone@gmail.com)
3 
4 Permission is hereby granted, free of charge, to any person or organization
5 obtaining a copy of the software and accompanying documentation covered by
6 this license (the "Software") to use, reproduce, display, distribute,
7 execute, and transmit the Software, and to prepare derivative works of the
8 Software, and to permit third-parties to whom the Software is furnished to
9 do so, all subject to the following:
10 
11 The copyright notices in the Software and this entire statement, including
12 the above license grant, this restriction and the following disclaimer,
13 must be included in all copies of the Software, in whole or in part, and
14 all derivative works of the Software, unless such copies or derivative
15 works are solely in the form of machine-executable object code generated by
16 a source language processor.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25 */
26 module ppc.backend;
27 import ppc.backend.loaders.ppc;
28 import ppc.types;
29 import std.file;
30 import core.stdc.config;
31 public import ppc.backend.cfile;
32 public import ppc.backend.signatures;
33 
34 
35 // Aliases to make it easier for C developers to make distinctions in the C bindings.
36 alias int64_t = long;
37 alias uint64_t = ulong;
38 alias int32_t = int;
39 alias uint32_t = uint;
40 alias int16_t = short;
41 alias uint16_t = ushort;
42 
43 // Alias these fuckers so we're sure that they are the right thing
44 alias clong = c_long;
45 alias culong = c_ulong;
46 
47 /++
48     A vector
49 +/
50 struct PVector {
51     /// X coordinate
52     ptrdiff_t x;
53 
54     /// Y coordinate
55     ptrdiff_t y;
56 }
57 
58 /++
59     A vector that contains size
60 +/
61 struct PSize {
62     /// Height
63     size_t width;
64 
65     /// Width
66     size_t height;
67 }
68 
69 struct PPCCreateInfo {
70     char[32] author;
71     char[16] license;
72 }
73 
74 Types compileToPPC(string file, string outFile, PPCCreateInfo createInfo) {
75     Types t = file.getTypeOf;
76     PPC ppc;
77     ppc.contentType = t;
78     ppc.author = createInfo.author;
79     ppc.license = createInfo.license;
80     ppc.options = 0;
81     ppc.version_ = 1;
82     ppc.setData(cast(ubyte[])read(file));
83 
84     write(outFile, savePPC(ppc));
85     return t;
86 }
87 
88 Types compileToPPC(ubyte[] data, Types t, string outFile, PPCCreateInfo createInfo) {
89     PPC ppc;
90     ppc.contentType = t;
91     ppc.author = createInfo.author;
92     ppc.license = createInfo.license;
93     ppc.options = 0;
94     ppc.version_ = 1;
95     ppc.setData(data);
96 
97     write(outFile, savePPC(ppc));
98     return t;
99 }
100 
101 shared static this() {
102     import ppc.backend.loaders.audio.ogg : initOGG;
103     import ppc.backend.ft : initFT;
104     initOGG();
105     initFT();
106 }