├── .gitignore
├── Compressor
├── Compressor.vcxproj
├── Compressor.vcxproj.filters
├── res
│ ├── config.xml
│ └── metadata.xml
└── src
│ ├── BufferStream.cpp
│ ├── BufferStream.h
│ ├── CompressionFormat.h
│ ├── Compressor.cpp
│ ├── Compressor.h
│ ├── Sprite.cpp
│ ├── Sprite.h
│ └── main.cpp
├── Decompressor.Android
├── AndroidManifest.xml
├── Decompressor.Android.vcxproj
├── Decompressor.Android.vcxproj.filters
├── jni
│ ├── com_thecherno_decompressor_Decompressor.cpp
│ ├── com_thecherno_decompressor_Decompressor.h
│ ├── com_thecherno_decompressor_DisplayActivity_DisplayRenderer.cpp
│ └── com_thecherno_decompressor_DisplayActivity_DisplayRenderer.h
├── res
│ ├── layout
│ │ ├── display_layout.xml
│ │ └── main_layout.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── com
│ └── thecherno
│ └── decompressor
│ ├── Decompressor.java
│ └── DisplayActivity.java
├── Decompressor.Windows
├── Decompressor.Windows.vcxproj
├── Decompressor.Windows.vcxproj.filters
└── src
│ └── main.cpp
├── Decompressor
├── Decompressor.vcxproj
├── Decompressor.vcxproj.filters
└── src
│ ├── Common.cpp
│ ├── Common.h
│ ├── DecompressionTest.cpp
│ ├── DecompressionTest.h
│ ├── Decompressor.cpp
│ └── Decompressor.h
├── Dependencies
├── LZ4
│ ├── LZ4.vcxproj
│ ├── LZ4.vcxproj.filters
│ ├── ProjectUpgradeBackup_20160825_1847191070
│ │ └── LZ4.vcxproj
│ ├── ProjectUpgradeBackup_20160825_1847191160
│ │ └── LZ4.vcxproj.filters
│ └── src
│ │ ├── lz4.c
│ │ └── lz4.h
├── STB
│ └── include
│ │ └── stb_image.h
└── zstd
│ ├── src
│ ├── common
│ │ ├── bitstream.h
│ │ ├── entropy_common.c
│ │ ├── error_private.h
│ │ ├── error_public.h
│ │ ├── fse.h
│ │ ├── fse_decompress.c
│ │ ├── huf.h
│ │ ├── mem.h
│ │ ├── xxhash.c
│ │ ├── xxhash.h
│ │ ├── zbuff.h
│ │ ├── zstd_common.c
│ │ └── zstd_internal.h
│ ├── compress
│ │ ├── fse_compress.c
│ │ ├── huf_compress.c
│ │ ├── zbuff_compress.c
│ │ ├── zstd_compress.c
│ │ └── zstd_opt.h
│ ├── decompress
│ │ ├── huf_decompress.c
│ │ ├── zbuff_decompress.c
│ │ └── zstd_decompress.c
│ └── zstd.h
│ ├── zstd.vcxproj
│ └── zstd.vcxproj.filters
├── Flinty
├── Dependencies
│ ├── GLEW
│ │ ├── GLEW.vcxproj
│ │ ├── GLEW.vcxproj.filters
│ │ ├── include
│ │ │ └── GL
│ │ │ │ ├── eglew.h
│ │ │ │ ├── glew.h
│ │ │ │ ├── glxew.h
│ │ │ │ └── wglew.h
│ │ └── src
│ │ │ ├── glew.c
│ │ │ ├── glewinfo.c
│ │ │ └── visualinfo.c
│ └── GLFW
│ │ ├── include
│ │ └── GLFW
│ │ │ ├── glfw3.h
│ │ │ └── glfw3native.h
│ │ └── lib
│ │ └── x86
│ │ └── glfw3.lib
└── Flinty
│ ├── Flinty.vcxproj
│ ├── Flinty.vcxproj.filters
│ └── src
│ ├── Flinty.h
│ └── fl
│ ├── Common.h
│ ├── Core.cpp
│ ├── Core.h
│ ├── String.cpp
│ ├── String.h
│ ├── Types.h
│ ├── gl.h
│ ├── graphics
│ ├── Renderer.cpp
│ ├── Renderer.h
│ ├── Window.cpp
│ ├── Window.h
│ └── shaders
│ │ ├── Shader.cpp
│ │ ├── Shader.h
│ │ ├── ShaderFactory.cpp
│ │ ├── ShaderFactory.h
│ │ ├── ShaderManager.cpp
│ │ ├── ShaderManager.h
│ │ ├── ShaderResource.cpp
│ │ ├── ShaderResource.h
│ │ ├── ShaderUniform.cpp
│ │ ├── ShaderUniform.h
│ │ └── default
│ │ └── Simple.shader
│ ├── maths
│ ├── AABB.cpp
│ ├── AABB.h
│ ├── Quaternion.cpp
│ ├── Quaternion.h
│ ├── Rectangle.cpp
│ ├── Rectangle.h
│ ├── mat4.cpp
│ ├── mat4.h
│ ├── maths.h
│ ├── maths_func.h
│ ├── tvec2.h
│ ├── vec2.cpp
│ ├── vec2.h
│ ├── vec3.cpp
│ ├── vec3.h
│ ├── vec4.cpp
│ └── vec4.h
│ ├── platform
│ ├── android
│ │ ├── AndroidFileSystem.cpp
│ │ ├── AndroidRenderer.cpp
│ │ ├── AndroidSystem.cpp
│ │ └── AndroidSystem.h
│ └── windows
│ │ ├── WindowsFileSystem.cpp
│ │ └── WindowsRenderer.cpp
│ ├── system
│ ├── FileSystem.cpp
│ ├── FileSystem.h
│ └── Timer.h
│ └── xml
│ ├── XMLDocument.cpp
│ ├── XMLDocument.h
│ └── rapidxml
│ ├── license.txt
│ ├── manual.html
│ ├── rapidxml.hpp
│ ├── rapidxml_iterators.hpp
│ ├── rapidxml_print.hpp
│ └── rapidxml_utils.hpp
├── LICENSE
├── README.md
├── SpriteCompression.sln
└── SpriteCompression
├── App.config
├── Properties
└── AssemblyInfo.cs
├── SpriteCompression.csproj
└── src
├── Compressor.cs
├── Decompressor.cs
├── Program.cs
├── Sprite.cs
└── Utils.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
3 | *.db
4 | *.opendb
5 | *.vspx
6 | *.psess
7 | *.suo
8 | *.user
9 | *.png
10 | *.bin
--------------------------------------------------------------------------------
/Compressor/Compressor.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | {9c7cf380-1ac0-488b-9034-60c659947ce7}
30 |
31 |
32 | {01947db5-0f7d-47ec-ae58-d445a35764a7}
33 |
34 |
35 | {ceb28ea3-4b44-4c0d-bfd4-948644dc0b78}
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | {C83B9DE2-50D7-4A26-8252-156DDBB1DCF1}
46 | Compressor
47 | 8.1
48 |
49 |
50 |
51 | Application
52 | true
53 | v140
54 | MultiByte
55 |
56 |
57 | Application
58 | false
59 | v140
60 | true
61 | MultiByte
62 |
63 |
64 | Application
65 | true
66 | v140
67 | MultiByte
68 |
69 |
70 | Application
71 | false
72 | v140
73 | true
74 | MultiByte
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | $(SolutionDir)bin\$(Configuration)\$(Platform)\
96 | $(SolutionDir)bin\$(Configuration)\$(Platform)\Intermediates\$(ProjectName)
97 |
98 |
99 | $(SolutionDir)bin\$(Configuration)\$(Platform)\
100 | $(SolutionDir)bin\$(Configuration)\$(Platform)\Intermediates\$(ProjectName)
101 |
102 |
103 |
104 | Level3
105 | Disabled
106 | true
107 | $(SolutionDir)Dependencies\zstd\src;$(SolutionDir)Dependencies\LZ4\src;$(SolutionDir)Flinty\Flinty\src;$(SolutionDir)Dependencies\STB\include
108 | _CRT_SECURE_NO_WARNINGS;FL_DEBUG;FL_PLATFORM_WINDOWS;_MBCS;%(PreprocessorDefinitions)
109 |
110 |
111 |
112 |
113 | Level3
114 | Disabled
115 | true
116 |
117 |
118 |
119 |
120 | Level3
121 | MaxSpeed
122 | true
123 | true
124 | true
125 | $(SolutionDir)Dependencies\zstd\src;$(SolutionDir)Dependencies\LZ4\src;$(SolutionDir)Flinty\Flinty\src;$(SolutionDir)Dependencies\STB\include
126 | _CRT_SECURE_NO_WARNINGS;FL_PLATFORM_WINDOWS;_MBCS;%(PreprocessorDefinitions)
127 |
128 |
129 | true
130 | true
131 |
132 |
133 |
134 |
135 | Level3
136 | MaxSpeed
137 | true
138 | true
139 | true
140 |
141 |
142 | true
143 | true
144 |
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/Compressor/Compressor.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 |
--------------------------------------------------------------------------------
/Compressor/res/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Compress
4 |
5 | res/Butterfly
6 |
7 | 2
8 | 16
9 |
10 |
--------------------------------------------------------------------------------
/Compressor/res/metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 20
6 | 24
7 |
8 |
9 |
10 |
11 | 50
12 | 80
13 | 3
14 |
15 |
16 | 4
17 | 18
18 | 1
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Compressor/src/BufferStream.cpp:
--------------------------------------------------------------------------------
1 | #include "BufferStream.h"
2 |
3 | BufferStream::BufferStream(uint size)
4 | {
5 | if (size)
6 | m_Buffer = std::vector(size);
7 | }
8 |
9 | BufferStream::~BufferStream()
10 | {
11 | }
12 |
13 | void BufferStream::WriteInternal(const void* buffer, uint size)
14 | {
15 | m_Buffer.insert(m_Buffer.end(), (byte*)buffer, (byte*)buffer + size);
16 | }
17 |
18 | void BufferStream::WriteInternal(const void* buffer, uint size, uint offset)
19 | {
20 | memcpy(&m_Buffer[offset], (byte*)buffer, size);
21 | }
22 |
23 | void BufferStream::WriteBytes(const byte* data, uint size)
24 | {
25 | WriteInternal(data, size);
26 | }
27 |
28 | void BufferStream::WriteBytes(const byte* data, uint size, uint offset)
29 | {
30 | WriteInternal(data, size, offset);
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/Compressor/src/BufferStream.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | class BufferStream
6 | {
7 | private:
8 | std::vector m_Buffer;
9 | uint m_Position;
10 | public:
11 | BufferStream(uint size = 0);
12 | ~BufferStream();
13 |
14 | inline const byte* GetBuffer() const { return &m_Buffer[0]; }
15 | inline uint GetSize() const { return m_Buffer.size(); }
16 |
17 | void WriteBytes(const byte* data, uint size);
18 | void WriteBytes(const byte* data, uint size, uint offset);
19 |
20 | template
21 | void Write(const T* data, uint count = 1)
22 | {
23 | WriteInternal((const void*)data, sizeof(T) * count);
24 | }
25 |
26 | template
27 | void Write(const T* data, uint count, uint offset)
28 | {
29 | WriteInternal((const void*)data, sizeof(T) * count, offset);
30 | }
31 |
32 | private:
33 | void WriteInternal(const void* buffer, uint size);
34 | void WriteInternal(const void* buffer, uint size, uint offset);
35 | };
--------------------------------------------------------------------------------
/Compressor/src/CompressionFormat.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/String.h"
4 |
5 | typedef unsigned char byte;
6 | typedef unsigned short ushort;
7 | typedef unsigned int uint;
8 |
9 | struct Header
10 | {
11 | enum class CompressionType : byte
12 | {
13 | NONE = 0, LZ4 = 1, ZSTD = 2
14 | };
15 |
16 | enum class Format : byte
17 | {
18 | ARGB = 0
19 | };
20 |
21 | enum class AnimationMode : byte
22 | {
23 | NONE = 0, NORMAL = 1, LOOP = 2, PINGPONG = 3
24 | };
25 |
26 | byte h0, h1; // [ 0] 08 08
27 | byte v0, v1; // [ 2] Major/Minor version
28 | byte quality; // [ 4] 0-5
29 | CompressionType compression; // [ 5]
30 | Format format; // [ 6]
31 | byte r0; // [ 7] Reserved
32 | ushort frames; // [ 8] number of frames
33 | ushort width, height; // [10] Size of animation
34 | ushort padding; // [14]
35 | uint decompressionBound; // [16] Size of largest decompression stream
36 |
37 | struct Event
38 | {
39 | ushort eventNameLength;
40 | char* eventName;
41 | ushort startFrame, endFrame;
42 | };
43 |
44 | ushort eventCount;
45 | Event* events;
46 |
47 | struct Animation
48 | {
49 | ushort animationNameLength;
50 | char* animationName;
51 | uint startFrameOffset;
52 | ushort startFrameIndex;
53 | ushort endFrameIndex;
54 | AnimationMode mode;
55 | };
56 |
57 | ushort animationCount;
58 | Animation* animations;
59 | };
60 |
61 | struct Metadata
62 | {
63 | struct Event
64 | {
65 | String name;
66 | ushort startFrame, endFrame;
67 | };
68 |
69 | struct Animation
70 | {
71 | String name;
72 | ushort startFrame, endFrame;
73 | Header::AnimationMode mode;
74 | };
75 |
76 | std::vector events;
77 | std::vector animations;
78 | };
--------------------------------------------------------------------------------
/Compressor/src/Compressor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include "BufferStream.h"
5 | #include "Sprite.h"
6 |
7 | #include "CompressionFormat.h"
8 |
9 | class Compressor
10 | {
11 | private:
12 | int m_Quality;
13 | int m_SimilarityThreshold;
14 | Header::CompressionType m_CompressionMode;
15 | std::vector m_Sprites;
16 | Metadata m_Metadata;
17 | int m_WindowSize;
18 | uint m_DecompressionBound;
19 | std::unordered_map m_AnimationOffsets;
20 | public:
21 | Compressor(const std::vector& sprites, const Metadata& metadata, byte quality, Header::CompressionType compressionType, int windowSize);
22 | ~Compressor();
23 |
24 | void Compress(const String& toFile);
25 | private:
26 | void WriteHeader(BufferStream& stream);
27 | void WriteKeyframe(BufferStream& stream, const Sprite& sprite, ushort index);
28 | void WriteDeltaFrame(BufferStream& stream, const Sprite& frame, int* previousBuffer);
29 |
30 | int ChannelDiff(int c0, int c1);
31 |
32 | void EmitPacket(BufferStream& stream, int* pixels, int cursor, ushort skipped, ushort copied);
33 | byte* ApplyEntropyCompression(const byte* buffer, uint size, uint* outSize = nullptr);
34 |
35 | bool IsAnimation(ushort index);
36 | };
37 |
--------------------------------------------------------------------------------
/Compressor/src/Sprite.cpp:
--------------------------------------------------------------------------------
1 | #include "Sprite.h"
2 |
3 | #define STB_IMAGE_IMPLEMENTATION
4 | #include
5 |
6 | Sprite::Sprite(const String& path)
7 | {
8 | int c;
9 | int w, h;
10 | pixels = stbi_load(path.c_str(), &w, &h, &c, STBI_rgb_alpha);
11 | width = (uint)w;
12 | height = (uint)h;
13 | }
--------------------------------------------------------------------------------
/Compressor/src/Sprite.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | struct Sprite
6 | {
7 | uint width, height;
8 | byte* pixels;
9 |
10 | Sprite(const String& path);
11 | };
12 |
--------------------------------------------------------------------------------
/Compressor/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 | #include
7 |
8 | #include "Compressor.h"
9 |
10 | enum class Mode
11 | {
12 | NONE, DECOMPRESS, COMPRESS, CONFIG
13 | };
14 |
15 | static std::vector GetAllFiles(String path, const String& mask)
16 | {
17 | std::vector results;
18 | HANDLE hFind = INVALID_HANDLE_VALUE;
19 | WIN32_FIND_DATA ffd;
20 | String spec;
21 | std::stack directories;
22 |
23 | directories.push(path);
24 |
25 | while (!directories.empty()) {
26 | path = directories.top();
27 | spec = path + "/" + mask;
28 | directories.pop();
29 |
30 | hFind = FindFirstFile(spec.c_str(), &ffd);
31 | if (hFind == INVALID_HANDLE_VALUE) {
32 | return results;
33 | }
34 |
35 | do {
36 | if (strcmp(ffd.cFileName, ".") != 0 &&
37 | strcmp(ffd.cFileName, "..") != 0) {
38 | if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
39 | directories.push(path + "/" + ffd.cFileName);
40 | }
41 | else {
42 | results.push_back(path + "/" + ffd.cFileName);
43 | }
44 | }
45 | } while (FindNextFile(hFind, &ffd) != 0);
46 |
47 | if (GetLastError() != ERROR_NO_MORE_FILES) {
48 | FindClose(hFind);
49 | return results;
50 | }
51 |
52 | FindClose(hFind);
53 | hFind = INVALID_HANDLE_VALUE;
54 | }
55 |
56 | return results;
57 | }
58 |
59 | static void PrintUsage()
60 | {
61 | std::cout << "\tUsage: sc mode(compress|decompress) input-path output-path [quality]" << std::endl;
62 | }
63 |
64 | int main(int argc, char** argv)
65 | {
66 | if (argc < 3)
67 | {
68 | PrintUsage();
69 | return 1;
70 | }
71 |
72 | Mode mode = Mode::NONE;
73 | String m = argv[1];
74 | if (m == "decompress")
75 | mode = Mode::DECOMPRESS;
76 | else if (m == "compress")
77 | mode = Mode::COMPRESS;
78 | else if (m == "-f")
79 | mode = Mode::CONFIG;
80 |
81 | Metadata metadata;
82 | bool hasMetadata = false;
83 |
84 | FL_ASSERT(mode != Mode::NONE);
85 | // Defaults
86 | String input, output;
87 | byte compression = 0;
88 | byte quality = 0;
89 | int windowSize = 8;
90 | if (mode == Mode::CONFIG)
91 | {
92 | String file = argv[2];
93 |
94 | fl::XMLDocument document(file);
95 | fl::XMLNode* rootNode = document.FindNode("Config");
96 | FL_ASSERT(rootNode);
97 | fl::XMLNode* modeNode = rootNode->FindChild("Mode");
98 | bool compress = false;
99 | if (modeNode)
100 | compress = String(modeNode->value) == "Compress";
101 |
102 | if (compress)
103 | {
104 | fl::XMLNode* settingsNode = rootNode->FindChild("Compressor");
105 | if (settingsNode)
106 | {
107 | fl::XMLNode* inputNode = settingsNode->FindChild("Input");
108 | if (inputNode)
109 | input = inputNode->value;
110 | fl::XMLNode* outputNode = settingsNode->FindChild("Output");
111 | if (outputNode)
112 | output = outputNode->value;
113 | fl::XMLNode* qualityNode = settingsNode->FindChild("Quality");
114 | if (qualityNode)
115 | quality = atoi(qualityNode->value.c_str());
116 | fl::XMLNode* compressionNode = settingsNode->FindChild("Compression");
117 | if (compressionNode)
118 | compression = atoi(compressionNode->value.c_str());
119 | fl::XMLNode* windowSizeNode = settingsNode->FindChild("WindowSize");
120 | if (windowSizeNode)
121 | windowSize = atoi(windowSizeNode->value.c_str());
122 | }
123 | }
124 | }
125 | else
126 | {
127 | input = String(argv[2]);
128 | if (argc > 3)
129 | output = String(argv[3]);
130 |
131 | if (argc > 4)
132 | quality = (byte)atoi(argv[4]);
133 |
134 | if (argc > 5)
135 | compression = atoi(argv[5]);
136 |
137 | if (argc > 6)
138 | windowSize = atoi(argv[6]);
139 |
140 | if (argc > 7)
141 | {
142 | String metadataFile = argv[7];
143 |
144 | fl::XMLDocument document(metadataFile);
145 | fl::XMLNode* rootNode = document.FindNode("Metadata");
146 | FL_ASSERT(rootNode);
147 |
148 | for (fl::XMLNode& e : rootNode->FindChild("Events")->children)
149 | {
150 | Metadata::Event ev;
151 | ev.name = e.FindAttribute("name")->value;
152 | ev.startFrame = atoi(e.FindChild("StartFrame")->value.c_str());
153 | ev.endFrame = atoi(e.FindChild("EndFrame")->value.c_str());
154 | metadata.events.push_back(ev);
155 | }
156 |
157 | for (fl::XMLNode& a : rootNode->FindChild("Animations")->children)
158 | {
159 | Metadata::Animation anim;
160 | anim.name = a.FindAttribute("name")->value;
161 | anim.startFrame = atoi(a.FindChild("StartFrame")->value.c_str());
162 | anim.endFrame = atoi(a.FindChild("EndFrame")->value.c_str());
163 | anim.mode = (Header::AnimationMode)atoi(a.FindChild("Mode")->value.c_str());
164 | metadata.animations.push_back(anim);
165 | }
166 | hasMetadata = true;
167 | }
168 | }
169 |
170 | std::vector files = GetAllFiles(input, "*");
171 |
172 | std::cout << "Reading " << files.size() << " images... ";
173 | std::vector sprites;
174 | for (int i = 0; i < files.size(); i++)
175 | sprites.push_back(Sprite(files[i]));
176 | std::cout << "Done." << std::endl;
177 |
178 | Compressor compressor(sprites, metadata, quality, (Header::CompressionType)compression, windowSize);
179 | compressor.Compress(output);
180 |
181 | return 0;
182 | }
--------------------------------------------------------------------------------
/Decompressor.Android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Decompressor.Android/Decompressor.Android.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 11
5 |
6 |
7 |
8 | Debug
9 | Tegra-Android
10 |
11 |
12 | Release
13 | Tegra-Android
14 |
15 |
16 | Shipping
17 | Tegra-Android
18 |
19 |
20 |
21 | {6C87890C-D661-4E0D-9F59-DB2A935EA075}
22 | Decompressor_Android
23 |
24 |
25 |
26 | android-21
27 | clang-3.6
28 | llvm-libc++_static
29 | GradleBuild
30 | UseTarget
31 |
32 |
33 | android-22
34 | clang-3.6
35 | llvm-libc++_static
36 | GradleBuild
37 |
38 |
39 | android-22
40 | clang-3.6
41 | llvm-libc++_static
42 | GradleBuild
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | $(SolutionDir)bin\$(Configuration)\$(Platform)\
51 | $(SolutionDir)bin\$(Configuration)\$(Platform)\Intermediates\$(ProjectName)
52 | false
53 |
54 |
55 | $(SolutionDir)bin\$(Configuration)\$(Platform)\
56 | $(SolutionDir)bin\$(Configuration)\$(Platform)\Intermediates\$(ProjectName)
57 | false
58 |
59 |
60 | $(SolutionDir)bin\$(Configuration)\$(Platform)\
61 | $(SolutionDir)bin\$(Configuration)\$(Platform)\Intermediates\$(ProjectName)
62 |
63 |
64 |
65 | gnu++11
66 | $(SolutionDir)Flinty\Flinty\src;$(SolutionDir)Decompressor\src;D:\NVPACK\android-ndk-r10e\platforms\android-21\arch-arm\usr\include
67 | FL_PLATFORM_ANDROID;DEBUG;
68 |
69 |
70 | android;GLESv2;
71 | D:\NVPACK\android-ndk-r10e\platforms\android-21\arch-arm\usr\lib;
72 | true
73 |
74 |
75 | assets
76 | False
77 |
78 |
79 |
80 |
81 | gnu++11
82 | $(SolutionDir)Flinty\Flinty\src;$(SolutionDir)Decompressor\src;C:\NVPACK\android-ndk-r10e\platforms\android-21\arch-arm\usr\include;
83 | FL_PLATFORM_ANDROID;
84 | O2
85 | false
86 |
87 |
88 | android;GLESv2;
89 | C:\NVPACK\android-ndk-r10e\platforms\android-21\arch-arm\usr\lib;
90 |
91 |
92 | assets
93 |
94 |
95 |
96 |
97 | gnu++11
98 | $(SolutionDir)Flinty\Flinty\src;$(SolutionDir)Decompressor\src;C:\NVPACK\android-ndk-r10e\platforms\android-21\arch-arm\usr\include;
99 | FL_PLATFORM_ANDROID;
100 |
101 |
102 | android;GLESv2;
103 | C:\NVPACK\android-ndk-r10e\platforms\android-21\arch-arm\usr\lib;
104 |
105 |
106 | assets
107 |
108 |
109 |
110 |
111 | Designer
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 | {07e50ef7-c482-4fe6-a9f4-eaf5c9394157}
130 |
131 |
132 | {9c7cf380-1ac0-488b-9034-60c659947ce7}
133 |
134 |
135 | {ceb28ea3-4b44-4c0d-bfd4-948644dc0b78}
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/Decompressor.Android/Decompressor.Android.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 553221e4-f24e-4650-8b66-9b861c4116c6
6 |
7 |
8 | 63b4c268-7e9f-41b2-be67-902a59499e39
9 |
10 |
11 | a7b17329-621b-4c47-a5b5-117fb6f2feeb
12 |
13 |
14 | b1512e7e-be8c-4f61-a7d8-8de8b092a181
15 |
16 |
17 | 67de3b0f-e3f7-4258-b588-aa7ef70ca6c3
18 |
19 |
20 | 58abff5e-ae86-4c7e-8293-076e014e4292
21 |
22 |
23 | b49f06e3-0b98-48c7-8cfd-c07bab913f66
24 |
25 |
26 | {faaab4a3-95ad-45f1-8e8d-2a700825513c}
27 |
28 |
29 |
30 |
31 |
32 | res\values
33 |
34 |
35 |
36 |
37 | jni
38 |
39 |
40 |
41 |
42 |
43 | jni
44 |
45 |
46 |
47 |
48 |
49 | src\com\thecherno\decompressor
50 |
51 |
52 | src\com\thecherno\decompressor
53 |
54 |
55 |
56 |
57 | res\layout
58 |
59 |
60 |
61 |
62 | res\layout
63 |
64 |
65 |
--------------------------------------------------------------------------------
/Decompressor.Android/jni/com_thecherno_decompressor_Decompressor.cpp:
--------------------------------------------------------------------------------
1 | #include "com_thecherno_decompressor_Decompressor.h"
2 | #include "DecompressionTest.h"
3 |
4 | using namespace fl;
5 |
6 | extern void UpdateAnimation(Animation* animation);
7 | extern Renderer* s_Renderer;
8 |
9 | JNIEXPORT jfloatArray JNICALL Java_com_thecherno_decompressor_Decompressor_RunDecompression(JNIEnv* env, jobject obj)
10 | {
11 | Init(env, obj);
12 | s_Renderer = new Renderer();
13 |
14 | DecompressionTest tester;
15 | std::vector results = tester.RunAllTests();
16 |
17 | Decompressor d("WS/512/butterfly512-uncompressed-ws16.bin");
18 | UpdateAnimation(d.Decompress3());
19 |
20 | uint count = results.size() * 2;
21 | jfloatArray result = env->NewFloatArray(count);
22 | if (!result)
23 | return nullptr;
24 |
25 | jfloat* data = new jfloat[count];
26 | for (int i = 0; i < results.size(); i++)
27 | {
28 | data[i * 2 + 0] = (float)results[i].size;
29 | data[i * 2 + 1] = results[i].time;
30 | }
31 |
32 | env->SetFloatArrayRegion(result, 0, count, data);
33 | delete[] data;
34 | return result;
35 | }
36 |
--------------------------------------------------------------------------------
/Decompressor.Android/jni/com_thecherno_decompressor_Decompressor.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 |
4 | #ifndef _Included_com_thecherno_decompressor_Decompressor
5 | #define _Included_com_thecherno_decompressor_Decompressor
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | JNIEXPORT jfloatArray JNICALL Java_com_thecherno_decompressor_Decompressor_RunDecompression(JNIEnv *, jobject);
11 |
12 | #ifdef __cplusplus
13 | }
14 | #endif
15 | #endif
--------------------------------------------------------------------------------
/Decompressor.Android/jni/com_thecherno_decompressor_DisplayActivity_DisplayRenderer.cpp:
--------------------------------------------------------------------------------
1 | #include "com_thecherno_decompressor_DisplayActivity_DisplayRenderer.h"
2 |
3 | #include "Decompressor.h"
4 |
5 | #include
6 | #include
7 |
8 | using namespace fl;
9 |
10 | static Shader* s_Shader;
11 | static int s_Frame = 0;
12 | static int s_Time = 0;
13 |
14 | static float s_FrameTime = 0.0f;
15 | static float s_UpdateTimer = 0.0f;
16 | static float s_UpdateTick = 1.0f / 60.0f;
17 | static uint s_Frames = 0;
18 | static uint s_Updates = 0;
19 | static Timer s_Timer;
20 | static float s_SecondTimer = 0.0f;
21 |
22 | Renderer* s_Renderer;
23 |
24 | static Animation* s_Animation = nullptr;
25 | static uint s_TextureID = 0;
26 |
27 | static void OnUpdate()
28 | {
29 | s_Time++;
30 |
31 | if (s_Animation && s_Time % 2 == 0)
32 | {
33 | s_Frame = (s_Frame + 1) % s_Animation->frames;
34 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, s_Animation->width, s_Animation->height, GL_RGBA, GL_UNSIGNED_BYTE, s_Animation->data[s_Frame]);
35 | }
36 | }
37 |
38 | static void OnRender(Renderer& renderer)
39 | {
40 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL);
41 | }
42 |
43 | void UpdateAnimation(Animation* animation)
44 | {
45 | SUBMIT_RENDER_3(Animation*&, m_Animation, s_Animation,
46 | Animation*, m_NewAnimation, animation,
47 | uint&, m_TextureID, s_TextureID, {
48 | if (m_Animation)
49 | delete m_Animation;
50 |
51 | m_Animation = m_NewAnimation;
52 |
53 | if (m_TextureID)
54 | glDeleteTextures(1, &m_TextureID);
55 |
56 | glGenTextures(1, &m_TextureID);
57 | glActiveTexture(GL_TEXTURE0);
58 | glBindTexture(GL_TEXTURE_2D, m_TextureID);
59 |
60 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
61 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
62 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
63 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
64 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_NewAnimation->width, m_NewAnimation->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
65 | });
66 | }
67 |
68 | JNIEXPORT void JNICALL Java_com_thecherno_decompressor_DisplayActivity_00024DisplayRenderer_OnInit(JNIEnv *, jclass)
69 | {
70 | Renderer::Init();
71 |
72 | s_Shader = ShaderFactory::SimpleShader();
73 | ShaderManager::Add(s_Shader);
74 | s_Shader->Bind();
75 | maths::mat4 proj = maths::mat4::Orthographic(-9.0f, 9.0f, -16.0f, 16.0f, -1.0f, 1.0f);
76 | s_Shader->SetUniform("pr_matrix", (byte*)&proj);
77 |
78 | float vertices[] = {
79 | -8.5f, -8.5f, 0.0f, 0.0f, 1.0f,
80 | -8.5f, 8.5f, 0.0f, 0.0f, 0.0f,
81 | 8.5f, 8.5f, 0.0f, 1.0f, 0.0f,
82 | 8.5f, -8.5f, 0.0f, 1.0f, 1.0f
83 | };
84 |
85 | int indices[] = {
86 | 0, 1, 2, 2, 3, 0
87 | };
88 |
89 |
90 | uint buffer;
91 | glGenBuffers(1, &buffer);
92 | glBindBuffer(GL_ARRAY_BUFFER, buffer);
93 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
94 |
95 | uint ibo;
96 | glGenBuffers(1, &ibo);
97 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
98 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
99 |
100 | glEnableVertexAttribArray(0);
101 | glEnableVertexAttribArray(1);
102 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 0);
103 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (const void*)(3 * sizeof(float)));
104 | }
105 |
106 | JNIEXPORT void JNICALL Java_com_thecherno_decompressor_DisplayActivity_00024DisplayRenderer_OnSurfaceChanged(JNIEnv *, jclass, jint width, jint height)
107 | {
108 | float w = 9.0f;
109 | float h = 16.0f;
110 | if (width > height)
111 | {
112 | w = 16.0f;
113 | h = 9.0f;
114 | }
115 |
116 | maths::mat4 proj = maths::mat4::Orthographic(-w, w, -h, h, -1.0f, 1.0f);
117 | s_Shader->SetUniform("pr_matrix", (byte*)&proj);
118 | }
119 |
120 | JNIEXPORT void JNICALL Java_com_thecherno_decompressor_DisplayActivity_00024DisplayRenderer_OnDraw(JNIEnv *, jclass)
121 | {
122 | if (s_SecondTimer == 0.0f)
123 | s_SecondTimer = s_Timer.Elapsed();
124 |
125 | float now = s_Timer.ElapsedMillis();
126 | s_Renderer->Clear();
127 |
128 | if (now - s_UpdateTimer > s_UpdateTick)
129 | {
130 | OnUpdate();
131 | s_Updates++;
132 | s_UpdateTimer += s_UpdateTick;
133 | }
134 |
135 | {
136 | Timer frametime;
137 | OnRender(*s_Renderer);
138 | s_Renderer->Flush();
139 | s_Frames++;
140 | s_FrameTime = frametime.ElapsedMillis();
141 | }
142 |
143 | if (s_Timer.Elapsed() - s_SecondTimer > 1.0f)
144 | {
145 | s_SecondTimer++;
146 | FL_LOG("Perf: %d ups, %d fps", s_Updates, s_Frames);
147 | s_Updates = 0;
148 | s_Frames = 0;
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/Decompressor.Android/jni/com_thecherno_decompressor_DisplayActivity_DisplayRenderer.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_thecherno_decompressor_DisplayActivity_DisplayRenderer */
4 |
5 | #ifndef _Included_com_thecherno_decompressor_DisplayActivity_DisplayRenderer
6 | #define _Included_com_thecherno_decompressor_DisplayActivity_DisplayRenderer
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: com_thecherno_decompressor_DisplayActivity_DisplayRenderer
12 | * Method: OnInit
13 | * Signature: ()V
14 | */
15 | JNIEXPORT void JNICALL Java_com_thecherno_decompressor_DisplayActivity_00024DisplayRenderer_OnInit
16 | (JNIEnv *, jclass);
17 |
18 | /*
19 | * Class: com_thecherno_decompressor_DisplayActivity_DisplayRenderer
20 | * Method: OnSurfaceChanged
21 | * Signature: (II)V
22 | */
23 | JNIEXPORT void JNICALL Java_com_thecherno_decompressor_DisplayActivity_00024DisplayRenderer_OnSurfaceChanged
24 | (JNIEnv *, jclass, jint, jint);
25 |
26 | /*
27 | * Class: com_thecherno_decompressor_DisplayActivity_DisplayRenderer
28 | * Method: OnDraw
29 | * Signature: ()V
30 | */
31 | JNIEXPORT void JNICALL Java_com_thecherno_decompressor_DisplayActivity_00024DisplayRenderer_OnDraw
32 | (JNIEnv *, jclass);
33 |
34 | #ifdef __cplusplus
35 | }
36 | #endif
37 | #endif
38 |
--------------------------------------------------------------------------------
/Decompressor.Android/res/layout/display_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
--------------------------------------------------------------------------------
/Decompressor.Android/res/layout/main_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
23 |
24 |
30 |
31 |
37 |
38 |
44 |
45 |
51 |
52 |
56 |
57 |
64 |
65 |
72 |
73 |
--------------------------------------------------------------------------------
/Decompressor.Android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Decompressor
4 |
5 | #ffffff
6 | #000000
7 |
8 |
--------------------------------------------------------------------------------
/Decompressor.Android/src/com/thecherno/decompressor/Decompressor.java:
--------------------------------------------------------------------------------
1 | package com.thecherno.decompressor;
2 |
3 | import android.app.Activity;
4 | import android.widget.TextView;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.content.Intent;
9 | import android.util.Log;
10 | import java.net.*;
11 | import java.io.*;
12 |
13 | public class Decompressor extends Activity
14 | {
15 | static {
16 | System.loadLibrary("Decompressor.Android");
17 | }
18 |
19 | private final static String TAG = "Decompressor";
20 | private TextView[] m_TextViews;
21 | private final static String SERVER = "https://thecherno.com/compression/dump.php";
22 |
23 | @Override
24 | public void onCreate(Bundle savedInstanceState)
25 | {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.main_layout);
28 |
29 | m_TextViews = new TextView[] {
30 | (TextView)findViewById(R.id.labelTitle01),
31 | (TextView)findViewById(R.id.labelSubtitle01),
32 | (TextView)findViewById(R.id.labelResult01),
33 | (TextView)findViewById(R.id.labelTitle02),
34 | (TextView)findViewById(R.id.labelSubtitle02),
35 | (TextView)findViewById(R.id.labelResult02)
36 | };
37 |
38 | Run();
39 | }
40 |
41 | private String FormatData(float[] data)
42 | {
43 | String result = Build.MODEL + "\n";
44 | for (int i = 0; i < data.length; i += 2)
45 | {
46 | result += String.format("%.4f", data[i + 1]) + "," + BytesToString((long)data[i + 0]) + "\n";
47 | }
48 | return result;
49 | }
50 |
51 | private void SendData(final String destination, final float[] data)
52 | {
53 | new Thread(new Runnable()
54 | {
55 | public void run()
56 | {
57 | String string = FormatData(data);
58 | byte[] buffer = string.getBytes();
59 | try
60 | {
61 | URL url = new URL(destination);
62 | HttpURLConnection connection = (HttpURLConnection)url.openConnection();
63 | connection.setConnectTimeout(30000);
64 | connection.setReadTimeout(60000);
65 | connection.setUseCaches(false);
66 | connection.setDoInput(true);
67 |
68 | connection.setRequestMethod("POST");
69 | connection.setRequestProperty("Content-Type", "text/plain");
70 | connection.setRequestProperty("Content-Length", Integer.toString(buffer.length));
71 |
72 | OutputStream out = connection.getOutputStream();
73 | out.write(buffer);
74 | out.flush();
75 | out.close();
76 |
77 | InputStream in = connection.getInputStream();
78 | int status = connection.getResponseCode();
79 | Log.w(TAG, "HTTP status = " + status);
80 | }
81 | catch (IOException e)
82 | {
83 | Log.e(TAG, Log.getStackTraceString(e));
84 | }
85 | }
86 | }).start();
87 | }
88 |
89 | private void Run()
90 | {
91 | // Structure:
92 | // - filesize
93 | // - time
94 | float[] data = RunDecompression();
95 | SendData(SERVER, data);
96 |
97 | m_TextViews[0].setText("animation.bin");
98 | m_TextViews[1].setText((int)data[0] + " bytes");
99 | m_TextViews[2].setText(data[1] + " ms");
100 |
101 | m_TextViews[3].setText("animation2.bin");
102 | m_TextViews[4].setText((int)data[2] + " bytes");
103 | String result = "";
104 | for (int i = 0; i < data.length && i < 12; i += 2)
105 | result += String.format("%.4f", data[i + 1]) + " ms (" + BytesToString((long)data[i + 0]) + ")\n";
106 | m_TextViews[5].setText(result);
107 | }
108 |
109 | public void OnRefreshButtonClick(View v)
110 | {
111 | Run();
112 | }
113 |
114 | public void OnViewButtonClick(View v)
115 | {
116 | Intent display = new Intent(getApplicationContext(), DisplayActivity.class);
117 | startActivity(display);
118 | }
119 |
120 | public native float[] RunDecompression();
121 |
122 | private String BytesToString(long bytes)
123 | {
124 | final float gb = 1024 * 1024 * 1024;
125 | final float mb = 1024 * 1024;
126 | final float kb = 1024;
127 |
128 | String result;
129 | if (bytes > gb)
130 | result = String.format("%.2f GB", bytes / gb);
131 | else if (bytes > mb)
132 | result = String.format("%.2f MB", bytes / mb);
133 | else if (bytes > kb)
134 | result = String.format("%.2f KB", bytes / kb);
135 | else
136 | result = String.format("%d bytes", (int)bytes);
137 |
138 | return result;
139 | }
140 |
141 | }
--------------------------------------------------------------------------------
/Decompressor.Android/src/com/thecherno/decompressor/DisplayActivity.java:
--------------------------------------------------------------------------------
1 | package com.thecherno.decompressor;
2 |
3 | import android.app.Activity;
4 | import android.widget.TextView;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.content.Context;
8 | import android.opengl.*;
9 |
10 | import javax.microedition.khronos.opengles.GL10;
11 | import javax.microedition.khronos.egl.EGLConfig;
12 |
13 | public class DisplayActivity extends Activity implements Runnable
14 | {
15 |
16 | public class DisplayRenderer implements GLSurfaceView.Renderer
17 | {
18 | private native void OnInit();
19 | private native void OnSurfaceChanged(int width, int height);
20 | private native void OnDraw();
21 |
22 | public void onSurfaceCreated(GL10 unused, EGLConfig config)
23 | {
24 | OnInit();
25 | }
26 |
27 | public void onDrawFrame(GL10 unused)
28 | {
29 | OnDraw();
30 | }
31 |
32 | public void onSurfaceChanged(GL10 unused, int width, int height)
33 | {
34 | OnSurfaceChanged(width, height);
35 | }
36 | }
37 |
38 | public class DecompressorSurface extends GLSurfaceView
39 | {
40 | private DisplayRenderer m_Renderer;
41 |
42 | public DecompressorSurface(Context context)
43 | {
44 | super(context);
45 |
46 | // Create an OpenGL ES 2.0 context
47 | setEGLContextClientVersion(2);
48 |
49 | m_Renderer = new DisplayRenderer();
50 | setRenderer(m_Renderer);
51 | }
52 | }
53 |
54 |
55 | private GLSurfaceView m_SurfaceView;
56 |
57 | @Override
58 | public void onCreate(Bundle savedInstanceState)
59 | {
60 | super.onCreate(savedInstanceState);
61 |
62 | m_SurfaceView = new DecompressorSurface(this);
63 | setContentView(m_SurfaceView);
64 |
65 | new Thread(this).start();
66 | }
67 |
68 | public void run()
69 | {
70 |
71 | }
72 |
73 |
74 |
75 | }
--------------------------------------------------------------------------------
/Decompressor.Windows/Decompressor.Windows.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Decompressor.Windows/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Common.h"
2 |
3 | #include "Decompressor.h"
4 | #include "DecompressionTest.h"
5 |
6 | #include "Flinty.h"
7 | #include
8 |
9 | // Extra stuff for stb
10 | static unsigned char stbbuffer[1024 * 1024 * 10];
11 | static unsigned char* stbtop = stbbuffer;
12 | #define STBI_MALLOC(x) stbtop; stbtop += x;
13 | #define STBI_FREE(x)
14 | #define STBI_REALLOC(x, y) stbtop; if (x) memcpy(stbtop, x, y); stbtop += y;
15 | #define STB_IMAGE_IMPLEMENTATION
16 | #include
17 |
18 | using namespace fl;
19 |
20 | static Window* s_Window;
21 | static Shader* s_Shader;
22 | static Animation* s_Animation;
23 | static int s_Frame = 0;
24 | static int s_Timer = 0;
25 |
26 | static void OnUpdate()
27 | {
28 | //std::cout << s_Window->GetFrameTime() << std::endl;
29 |
30 | s_Timer++;
31 | if (s_Animation && s_Timer % 2 == 0)
32 | {
33 | s_Frame = (s_Frame + 1) % s_Animation->frames;
34 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, s_Animation->width, s_Animation->height, GL_RGBA, GL_UNSIGNED_BYTE, s_Animation->data[s_Frame]);
35 | }
36 | }
37 |
38 | static void OnRender(Renderer& renderer)
39 | {
40 | renderer.SetClearColor(1.0f, 1.0f, 1.0f, 1.0f);
41 |
42 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL);
43 | }
44 |
45 | static void OnKeyEvent(int key, int action)
46 | {
47 | }
48 |
49 |
50 | void ReadPNG(byte* png, long bsize)
51 | {
52 | stbtop = stbbuffer;
53 | int x, y;
54 | stbi_load_from_memory((stbi_uc*)png, bsize, &x, &y, nullptr, 0);
55 | }
56 |
57 | int main()
58 | {
59 | Window window("Sandbox", 1280, 720);
60 | s_Window = &window;
61 |
62 | window.SetUpdateCallback(OnUpdate);
63 | window.SetRenderCallback(OnRender);
64 | window.SetKeyCallback(OnKeyEvent);
65 |
66 | s_Shader = ShaderFactory::SimpleShader();
67 | ShaderManager::Add(s_Shader);
68 | s_Shader->Bind();
69 | s_Shader->SetUniform("pr_matrix", (byte*)&maths::mat4::Orthographic(-16.0f, 16.0f, -9.0f, 9.0f, -1.0f, 1.0f));
70 |
71 | float vertices[] = {
72 | -4.5f, -4.5f, 0.0f, 0.0f, 1.0f,
73 | -4.5f, 4.5f, 0.0f, 0.0f, 0.0f,
74 | 4.5f, 4.5f, 0.0f, 1.0f, 0.0f,
75 | 4.5f, -4.5f, 0.0f, 1.0f, 1.0f
76 | };
77 |
78 | int indices[] = {
79 | 0, 1, 2, 2, 3, 0
80 | };
81 |
82 | glEnable(GL_BLEND);
83 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
84 |
85 | uint buffer;
86 | glGenBuffers(1, &buffer);
87 | glBindBuffer(GL_ARRAY_BUFFER, buffer);
88 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
89 |
90 | uint ibo;
91 | glGenBuffers(1, &ibo);
92 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
93 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
94 |
95 | glEnableVertexAttribArray(0);
96 | glEnableVertexAttribArray(1);
97 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 0);
98 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (const void*)(3 * sizeof(float)));
99 |
100 | #if 0
101 | {
102 | float time = 0.0f;
103 | byte* buffer[128];
104 | long bsize[128];
105 | for (int i = 0; i < 128; i++)
106 | {
107 | char filename[128];
108 | sprintf(filename, "control/%04d.png", i + 1);
109 | buffer[i] = ReadFile(filename, &bsize[i]);
110 | }
111 | Timer timer;
112 | for (int i = 0; i < 1; i++)
113 | {
114 | for (int j = 0; j < 128; j++)
115 | {
116 | if (buffer[j] == 0)
117 | break;
118 | ReadPNG(buffer[j], bsize[j]);
119 | }
120 | }
121 | time += timer.ElapsedMillis();
122 | std::cout << time << "ms" << std::endl;
123 | }
124 |
125 | {
126 | float time = 0.0f;
127 | Decompressor decompressor("animation.bin");
128 | Timer timer;
129 | for (int i = 0; i < 1000; i++)
130 | {
131 | decompressor.Decompress();
132 | }
133 | time += timer.ElapsedMillis();
134 | std::cout << time << "ms" << std::endl;
135 | }
136 |
137 | {
138 | float time = 0.0f;
139 | Decompressor decompressor("animation2.bin");
140 | Timer timer;
141 | for (int i = 0; i < 1000; i++)
142 | {
143 | decompressor.Decompress2();
144 | }
145 | time += timer.ElapsedMillis();
146 | std::cout << time << "ms" << std::endl;
147 | }
148 |
149 | {
150 | float time = 0.0f;
151 | Decompressor decompressor("animation3.bin");
152 | Timer timer;
153 | for (int i = 0; i < 1000; i++)
154 | {
155 | decompressor.Decompress2();
156 | }
157 | time += timer.ElapsedMillis();
158 | std::cout << time << "ms" << std::endl;
159 | }
160 |
161 | #endif
162 |
163 | /*DecompressionTest test;
164 | std::vector results = test.RunAllTests();
165 | for (int i = 0; i < results.size(); i++)
166 | {
167 | FL_LOG("%s: %.4fms (%d bytes)", results[i].id.c_str(), results[i].time, results[i].size);
168 | }*/
169 |
170 |
171 | Animation* anim;
172 | {
173 | float time = 0.0f;
174 | Decompressor decompressor("butterfly512-lz4.bin");
175 | Timer timer;
176 | anim = decompressor.Decompress();
177 | time += timer.ElapsedMillis();
178 | std::cout << time << "ms" << std::endl;
179 | }
180 | {
181 | float time = 0.0f;
182 | Decompressor decompressor("new.bin");
183 | Timer timer;
184 | decompressor.Decompress();
185 | time += timer.ElapsedMillis();
186 |
187 | std::cout << time << "ms" << std::endl;
188 | }
189 |
190 | s_Animation = anim;
191 |
192 | uint texture;
193 | glGenTextures(1, &texture);
194 | glActiveTexture(GL_TEXTURE0);
195 | glBindTexture(GL_TEXTURE_2D, texture);
196 |
197 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
198 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
199 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
200 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
201 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, anim->width, anim->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
202 |
203 | window.Show();
204 |
205 | return 0;
206 | }
--------------------------------------------------------------------------------
/Decompressor/Decompressor.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Decompressor/src/Common.cpp:
--------------------------------------------------------------------------------
1 | #include "Common.h"
--------------------------------------------------------------------------------
/Decompressor/src/Common.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 |
--------------------------------------------------------------------------------
/Decompressor/src/DecompressionTest.cpp:
--------------------------------------------------------------------------------
1 | #include "DecompressionTest.h"
2 |
3 | using namespace fl;
4 |
5 | static const int s_IterationCount = 10;
6 |
7 | DecompressionTest::DecompressionTest(const String& assetsDirectory)
8 | : m_AssetsDirectory(assetsDirectory)
9 | {
10 | if (assetsDirectory.size() && assetsDirectory[assetsDirectory.size() - 1] != '/')
11 | m_AssetsDirectory += '/';
12 | }
13 |
14 | std::vector DecompressionTest::RunAllTests()
15 | {
16 | // std::vector uncompressedWindowResults256 = RunWindowTests("256", "uncompressed");
17 | // std::vector lz4WindowResults256 = RunWindowTests("256", "lz4");
18 | std::vector uncompressedWindowResults512 = RunWindowTests("512", "uncompressed");
19 | std::vector lz4WindowResults512 = RunWindowTests("512", "lz4");
20 | std::vector zstdWindowResults512 = RunWindowTests("512", "zstd");
21 |
22 | std::vector results;
23 | // results.insert(results.end(), uncompressedWindowResults256.begin(), uncompressedWindowResults256.end());
24 | // results.insert(results.end(), lz4WindowResults256.begin(), lz4WindowResults256.end());
25 | results.insert(results.end(), uncompressedWindowResults512.begin(), uncompressedWindowResults512.end());
26 | results.insert(results.end(), lz4WindowResults512.begin(), lz4WindowResults512.end());
27 | results.insert(results.end(), zstdWindowResults512.begin(), zstdWindowResults512.end());
28 | return results;
29 | }
30 |
31 | std::vector DecompressionTest::RunWindowTests(const String& size, const String& compression)
32 | {
33 | const int count = 7;
34 | const String files[count] = {
35 | "ws0", "ws8", "ws16", "ws24", "ws32","ws40", "ws48"
36 | };
37 |
38 | float timeBuffer[s_IterationCount];
39 |
40 | std::vector results(count);
41 | for (int i = 0; i < count; i++)
42 | {
43 | String path = m_AssetsDirectory + "WS/" + size + "/butterfly" + size + "-" + compression + "-" + files[i] + ".bin";
44 | byte* buffer = fl::FileSystem::ReadFile(path, &results[i].size);
45 | FL_ASSERT(buffer);
46 | Decompressor decompressor(buffer, results[i].size);
47 |
48 | for (int i = 0; i < s_IterationCount; i++)
49 | {
50 | Timer timer;
51 | decompressor.DecompressBenchmark();
52 | timeBuffer[i] = timer.ElapsedMillis();
53 | }
54 | results[i].time = GetMin(timeBuffer, s_IterationCount);
55 | results[i].id = path;
56 | }
57 |
58 | return results;
59 | }
60 |
61 | std::vector DecompressionTest::RunUncompressedTests()
62 | {
63 | std::vector results(1);
64 | String path = m_AssetsDirectory + "WS/512/butterfly512-uncompressed-ws16.bin";
65 | byte* buffer = fl::FileSystem::ReadFile(path, &results[0].size);
66 | FL_ASSERT(buffer);
67 | Decompressor decompressor(buffer, results[0].size);
68 | float timeBuffer[s_IterationCount];
69 | for (int i = 0; i < s_IterationCount; i++)
70 | {
71 | Timer timer;
72 | decompressor.DecompressBenchmark();
73 | timeBuffer[i] = timer.ElapsedMillis();
74 | }
75 | results[0].time = GetMin(timeBuffer, s_IterationCount);
76 | results[0].id = path;
77 | return results;
78 | }
79 |
80 | std::vector DecompressionTest::RunLZ4Tests()
81 | {
82 | std::vector results(1);
83 | String path = m_AssetsDirectory + "WS/512/butterfly512-lz4-ws16.bin";
84 | byte* buffer = fl::FileSystem::ReadFile(path, &results[0].size);
85 | FL_ASSERT(buffer);
86 | Decompressor decompressor(buffer, results[0].size);
87 | float timeBuffer[s_IterationCount];
88 | for (int i = 0; i < s_IterationCount; i++)
89 | {
90 | Timer timer;
91 | decompressor.DecompressBenchmark();
92 | timeBuffer[i] = timer.ElapsedMillis();
93 | }
94 | results[0].time = GetMin(timeBuffer, s_IterationCount);
95 | results[0].id = path;
96 | return results;
97 | }
98 |
99 | float DecompressionTest::GetMin(float* array, int size)
100 | {
101 | float min = FLT_MAX;
102 | for (int i = 0; i < size; i++)
103 | {
104 | if (array[i] < min)
105 | min = array[i];
106 | }
107 | return min;
108 | }
--------------------------------------------------------------------------------
/Decompressor/src/DecompressionTest.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Common.h"
4 | #include "Decompressor.h"
5 |
6 | struct DecompressionResult
7 | {
8 | String id;
9 | float time;
10 | size_t size;
11 | Animation* animation;
12 | };
13 |
14 | class DecompressionTest
15 | {
16 | private:
17 | String m_AssetsDirectory;
18 | public:
19 | DecompressionTest(const String& assetsDirectory = "");
20 |
21 | std::vector RunAllTests();
22 | std::vector RunWindowTests(const String& size, const String& compression);
23 | std::vector RunLZ4Tests();
24 | std::vector RunUncompressedTests();
25 | private:
26 | float GetMin(float* array, int size);
27 | };
--------------------------------------------------------------------------------
/Decompressor/src/Decompressor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | struct Animation
6 | {
7 | int width, height;
8 | int frames;
9 | std::vector data;
10 |
11 | inline ~Animation()
12 | {
13 | for (int i = 0; i < data.size(); i++)
14 | delete[] data[i];
15 | }
16 | };
17 |
18 | class Decompressor
19 | {
20 | private:
21 | byte* m_Buffer;
22 | size_t m_Size;
23 | public:
24 | Decompressor(const String& path);
25 | Decompressor(byte* buffer, long size);
26 | ~Decompressor();
27 |
28 | Animation* Decompress();
29 | void DecompressBenchmark();
30 |
31 | Animation* Decompress1();
32 | Animation* Decompress2();
33 | Animation* Decompress3();
34 | Animation* Decompress4();
35 | void Decompress2Benchmark();
36 |
37 | Animation* Deserialize3(byte* buffer, long size);
38 | void Deserialize3Benchmark(byte* buffer, long size);
39 |
40 | Animation* Deserialize4(byte* buffer, long size);
41 | void Deserialize4Benchmark(byte* buffer, long size);
42 | private:
43 | byte* DecompressLZ4(const byte* buffer, uint size, uint decompressedSize);
44 | byte* DecompressZSTD(const byte* buffer, uint size, uint decompressedSize);
45 | };
46 |
--------------------------------------------------------------------------------
/Dependencies/LZ4/LZ4.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Dependencies/LZ4/ProjectUpgradeBackup_20160825_1847191160/LZ4.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Dependencies/zstd/src/common/error_private.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | /* Note : this module is expected to remain private, do not expose it */
11 |
12 | #ifndef ERROR_H_MODULE
13 | #define ERROR_H_MODULE
14 |
15 | #if defined (__cplusplus)
16 | extern "C" {
17 | #endif
18 |
19 |
20 | /* ****************************************
21 | * Dependencies
22 | ******************************************/
23 | #include /* size_t */
24 | #include "error_public.h" /* enum list */
25 |
26 |
27 | /* ****************************************
28 | * Compiler-specific
29 | ******************************************/
30 | #if defined(__GNUC__)
31 | # define ERR_STATIC static __attribute__((unused))
32 | #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
33 | # define ERR_STATIC static inline
34 | #elif defined(_MSC_VER)
35 | # define ERR_STATIC static __inline
36 | #else
37 | # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
38 | #endif
39 |
40 |
41 | /*-****************************************
42 | * Customization (error_public.h)
43 | ******************************************/
44 | typedef ZSTD_ErrorCode ERR_enum;
45 | #define PREFIX(name) ZSTD_error_##name
46 |
47 |
48 | /*-****************************************
49 | * Error codes handling
50 | ******************************************/
51 | #ifdef ERROR
52 | # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
53 | #endif
54 | #define ERROR(name) ((size_t)-PREFIX(name))
55 |
56 | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
57 |
58 | ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
59 |
60 |
61 | /*-****************************************
62 | * Error Strings
63 | ******************************************/
64 |
65 | ERR_STATIC const char* ERR_getErrorString(ERR_enum code)
66 | {
67 | static const char* notErrorCode = "Unspecified error code";
68 | switch( code )
69 | {
70 | case PREFIX(no_error): return "No error detected";
71 | case PREFIX(GENERIC): return "Error (generic)";
72 | case PREFIX(prefix_unknown): return "Unknown frame descriptor";
73 | case PREFIX(version_unsupported): return "Version not supported";
74 | case PREFIX(parameter_unknown): return "Unknown parameter type";
75 | case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
76 | case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode";
77 | case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound";
78 | case PREFIX(init_missing): return "Context should be init first";
79 | case PREFIX(memory_allocation): return "Allocation error : not enough memory";
80 | case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
81 | case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
82 | case PREFIX(srcSize_wrong): return "Src size incorrect";
83 | case PREFIX(corruption_detected): return "Corrupted block detected";
84 | case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
85 | case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
86 | case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
87 | case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
88 | case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
89 | case PREFIX(dictionary_wrong): return "Dictionary mismatch";
90 | case PREFIX(maxCode):
91 | default: return notErrorCode;
92 | }
93 | }
94 |
95 | ERR_STATIC const char* ERR_getErrorName(size_t code)
96 | {
97 | return ERR_getErrorString(ERR_getErrorCode(code));
98 | }
99 |
100 | #if defined (__cplusplus)
101 | }
102 | #endif
103 |
104 | #endif /* ERROR_H_MODULE */
105 |
--------------------------------------------------------------------------------
/Dependencies/zstd/src/common/error_public.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #ifndef ERROR_PUBLIC_H_MODULE
11 | #define ERROR_PUBLIC_H_MODULE
12 |
13 | #if defined (__cplusplus)
14 | extern "C" {
15 | #endif
16 |
17 | /*===== dependency =====*/
18 | #include /* size_t */
19 |
20 |
21 | /*-****************************************
22 | * error codes list
23 | ******************************************/
24 | typedef enum {
25 | ZSTD_error_no_error,
26 | ZSTD_error_GENERIC,
27 | ZSTD_error_prefix_unknown,
28 | ZSTD_error_version_unsupported,
29 | ZSTD_error_parameter_unknown,
30 | ZSTD_error_frameParameter_unsupported,
31 | ZSTD_error_frameParameter_unsupportedBy32bits,
32 | ZSTD_error_compressionParameter_unsupported,
33 | ZSTD_error_init_missing,
34 | ZSTD_error_memory_allocation,
35 | ZSTD_error_stage_wrong,
36 | ZSTD_error_dstSize_tooSmall,
37 | ZSTD_error_srcSize_wrong,
38 | ZSTD_error_corruption_detected,
39 | ZSTD_error_checksum_wrong,
40 | ZSTD_error_tableLog_tooLarge,
41 | ZSTD_error_maxSymbolValue_tooLarge,
42 | ZSTD_error_maxSymbolValue_tooSmall,
43 | ZSTD_error_dictionary_corrupted,
44 | ZSTD_error_dictionary_wrong,
45 | ZSTD_error_maxCode
46 | } ZSTD_ErrorCode;
47 |
48 | /*! ZSTD_getErrorCode() :
49 | convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
50 | which can be used to compare directly with enum list published into "error_public.h" */
51 | ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
52 | const char* ZSTD_getErrorString(ZSTD_ErrorCode code);
53 |
54 |
55 | #if defined (__cplusplus)
56 | }
57 | #endif
58 |
59 | #endif /* ERROR_PUBLIC_H_MODULE */
60 |
--------------------------------------------------------------------------------
/Dependencies/zstd/src/common/zstd_common.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 |
11 |
12 | /*-*************************************
13 | * Dependencies
14 | ***************************************/
15 | #include /* malloc */
16 | #include "error_private.h"
17 | #define ZSTD_STATIC_LINKING_ONLY
18 | #include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
19 | #include "zbuff.h" /* declaration of ZBUFF_isError, ZBUFF_getErrorName */
20 |
21 |
22 | /*-****************************************
23 | * Version
24 | ******************************************/
25 | unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
26 |
27 |
28 | /*-****************************************
29 | * ZSTD Error Management
30 | ******************************************/
31 | /*! ZSTD_isError() :
32 | * tells if a return value is an error code */
33 | unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
34 |
35 | /*! ZSTD_getErrorName() :
36 | * provides error code string from function result (useful for debugging) */
37 | const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
38 |
39 | /*! ZSTD_getError() :
40 | * convert a `size_t` function result into a proper ZSTD_errorCode enum */
41 | ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
42 |
43 | /*! ZSTD_getErrorString() :
44 | * provides error code string from enum */
45 | const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); }
46 |
47 |
48 | /* **************************************************************
49 | * ZBUFF Error Management
50 | ****************************************************************/
51 | unsigned ZBUFF_isError(size_t errorCode) { return ERR_isError(errorCode); }
52 |
53 | const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); }
54 |
55 |
56 |
57 | /*=**************************************************************
58 | * Custom allocator
59 | ****************************************************************/
60 | /* default uses stdlib */
61 | void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
62 | {
63 | void* address = malloc(size);
64 | (void)opaque;
65 | return address;
66 | }
67 |
68 | void ZSTD_defaultFreeFunction(void* opaque, void* address)
69 | {
70 | (void)opaque;
71 | free(address);
72 | }
73 |
74 | void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
75 | {
76 | return customMem.customAlloc(customMem.opaque, size);
77 | }
78 |
79 | void ZSTD_free(void* ptr, ZSTD_customMem customMem)
80 | {
81 | if (ptr!=NULL)
82 | customMem.customFree(customMem.opaque, ptr);
83 | }
84 |
--------------------------------------------------------------------------------
/Dependencies/zstd/zstd.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 | Header Files
41 |
42 |
43 | Header Files
44 |
45 |
46 | Header Files
47 |
48 |
49 | Header Files
50 |
51 |
52 |
53 |
54 | Source Files
55 |
56 |
57 | Source Files
58 |
59 |
60 | Source Files
61 |
62 |
63 | Source Files
64 |
65 |
66 | Source Files
67 |
68 |
69 | Source Files
70 |
71 |
72 | Source Files
73 |
74 |
75 | Source Files
76 |
77 |
78 | Source Files
79 |
80 |
81 | Source Files
82 |
83 |
84 | Source Files
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Flinty/Dependencies/GLEW/GLEW.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {6E0DEEF6-F4C2-4B7E-A2FE-BB9BAE5EC8D1}
23 | GLEW
24 | 8.1
25 |
26 |
27 |
28 | StaticLibrary
29 | true
30 | v140
31 | MultiByte
32 |
33 |
34 | StaticLibrary
35 | false
36 | v140
37 | true
38 | MultiByte
39 |
40 |
41 | Application
42 | true
43 | v140
44 | MultiByte
45 |
46 |
47 | Application
48 | false
49 | v140
50 | true
51 | MultiByte
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | $(SolutionDir)bin\$(Platform)\$(Configuration)\
73 | $(SolutionDir)bin\$(Platform)\$(Configuration)\Intermediates\$(ProjectName)\
74 |
75 |
76 | $(SolutionDir)bin\$(Platform)\$(Configuration)\
77 | $(SolutionDir)bin\$(Platform)\$(Configuration)\Intermediates\$(ProjectName)\
78 |
79 |
80 |
81 | Level3
82 | Disabled
83 | true
84 | include;
85 | _CRT_SECURE_NO_WARNINGS;GLEW_BUILD;_MBCS;%(PreprocessorDefinitions)
86 |
87 |
88 |
89 |
90 | Level3
91 | Disabled
92 | true
93 |
94 |
95 |
96 |
97 | Level3
98 | MaxSpeed
99 | true
100 | true
101 | true
102 | include;
103 | _CRT_SECURE_NO_WARNINGS;GLEW_BUILD;_MBCS;%(PreprocessorDefinitions)
104 |
105 |
106 | true
107 | true
108 |
109 |
110 |
111 |
112 | Level3
113 | MaxSpeed
114 | true
115 | true
116 | true
117 |
118 |
119 | true
120 | true
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/Flinty/Dependencies/GLEW/GLEW.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Flinty/Dependencies/GLFW/lib/x86/glfw3.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TheCherno/AnimatedSpriteCompression/012dc267c59a7921defed868d235533afa630b6b/Flinty/Dependencies/GLFW/lib/x86/glfw3.lib
--------------------------------------------------------------------------------
/Flinty/Flinty/Flinty.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 | Header Files
41 |
42 |
43 | Header Files
44 |
45 |
46 | Header Files
47 |
48 |
49 | Header Files
50 |
51 |
52 | Header Files
53 |
54 |
55 | Header Files
56 |
57 |
58 | Header Files
59 |
60 |
61 | Header Files
62 |
63 |
64 | Header Files
65 |
66 |
67 | Header Files
68 |
69 |
70 | Header Files
71 |
72 |
73 | Header Files
74 |
75 |
76 | Header Files
77 |
78 |
79 | Header Files
80 |
81 |
82 | Header Files
83 |
84 |
85 | Header Files
86 |
87 |
88 | Header Files
89 |
90 |
91 | Header Files
92 |
93 |
94 | Header Files
95 |
96 |
97 | Header Files
98 |
99 |
100 | Header Files
101 |
102 |
103 | Header Files
104 |
105 |
106 | Header Files
107 |
108 |
109 | Header Files
110 |
111 |
112 |
113 |
114 | Source Files
115 |
116 |
117 | Source Files
118 |
119 |
120 | Source Files
121 |
122 |
123 | Source Files
124 |
125 |
126 | Source Files
127 |
128 |
129 | Source Files
130 |
131 |
132 | Source Files
133 |
134 |
135 | Source Files
136 |
137 |
138 | Source Files
139 |
140 |
141 | Source Files
142 |
143 |
144 | Source Files
145 |
146 |
147 | Source Files
148 |
149 |
150 | Source Files
151 |
152 |
153 | Source Files
154 |
155 |
156 | Source Files
157 |
158 |
159 | Source Files
160 |
161 |
162 | Source Files
163 |
164 |
165 | Source Files
166 |
167 |
168 | Source Files
169 |
170 |
171 | Source Files
172 |
173 |
174 | Source Files
175 |
176 |
177 | Source Files
178 |
179 |
180 |
181 |
182 |
183 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/Flinty.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 |
13 | #include
14 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/Common.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "fl/Types.h"
6 |
7 | // TODO: Move to precompiled header
8 | #include
9 |
10 | // Common data structures
11 | #include
12 | #include
13 | #include
14 |
15 | #ifdef FL_PLATFORM_ANDROID
16 | #include
17 | #endif
18 |
19 | // Some typedefs to rename C++'s questionable names
20 | template using HashSet = std::unordered_set;
21 | template using HashMap = std::unordered_map;
22 |
23 | #ifdef FL_PLATFORM_WINDOWS
24 | #ifdef FL_CORE_DLL
25 | #define FL_API __declspec(dllexport)
26 | #else
27 | #define FL_API __declspec(dllimport)
28 | #endif
29 | #else
30 | #define FL_API
31 | #endif
32 |
33 | namespace fl {
34 | extern void GLClearError();
35 | extern bool GLLogCall(const char* function, const char* file, int line);
36 | }
37 |
38 | #ifdef FL_DEBUG
39 | #if defined(FL_PLATFORM_WINDOWS)
40 | #define FL_ASSERT(x) \
41 | if (!(x)) {\
42 | std::cout << "*************************" << std::endl; \
43 | std::cout << " ASSERTION FAILED! " << std::endl; \
44 | std::cout << "*************************" << std::endl; \
45 | std::cout << __FILE__ << ": " << __LINE__ << std::endl; \
46 | std::cout << "Condition: " << #x << std::endl; \
47 | __debugbreak(); \
48 | }
49 | #elif defined(FL_PLATFORM_ANDROID)
50 | #define FL_ASSERT(x) if (!(x)) { __asm__ volatile(".inst 0xd4200000"); }
51 | #endif
52 | #else
53 | #define FL_ASSERT(x, ...)
54 | #endif
55 |
56 |
57 | #ifdef FL_DEBUG
58 | #define GLCall(x) fl::GLClearError();\
59 | x; \
60 | if (!fl::GLLogCall(#x, __FILE__, __LINE__)) FL_ASSERT(false);
61 | #else
62 | #define GLCall(x) x
63 | #endif
64 |
65 | #if defined(FL_PLATFORM_WINDOWS)
66 | #define FL_LOG(string, ...) printf(string##"\n", __VA_ARGS__)
67 | #elif defined(FL_PLATFORM_ANDROID)
68 | #define FL_LOG(...) ((void)__android_log_print(ANDROID_LOG_WARN, "DecompressionTest", __VA_ARGS__))
69 | #endif
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/Core.cpp:
--------------------------------------------------------------------------------
1 | #include "Core.h"
2 |
3 | #include
4 | #include "gl.h"
5 |
6 | #if defined(FL_PLATFORM_ANDROID)
7 | #include "platform/android/AndroidSystem.h"
8 | #endif
9 |
10 | namespace fl {
11 |
12 | #if defined(FL_PLATFORM_WINDOWS)
13 |
14 | void Init()
15 | {
16 | }
17 |
18 | #elif defined(FL_PLATFORM_ANDROID)
19 |
20 | void Init(void* env, void* mainView)
21 | {
22 | AndroidSystem::Init((JNIEnv*)env, (jobject)mainView);
23 | }
24 |
25 | #endif
26 |
27 | inline GLenum GLCheckError()
28 | {
29 | return glGetError();
30 | }
31 |
32 | void GLClearError()
33 | {
34 | GLCheckError();
35 | }
36 |
37 | bool GLLogCall(const char* function, const char* file, int line)
38 | {
39 | while (GLenum error = GLCheckError())
40 | {
41 | std::cout << "[OpenGL Error] (" << error << "): " << function << " " << file << ":" << line << std::endl;
42 | return false;
43 | }
44 | return true;
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/Core.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Common.h"
4 |
5 | #if defined(FL_PLATFORM_ANDROID)
6 | #include "fl/platform/android/AndroidSystem.h"
7 | #endif
8 |
9 | namespace fl {
10 |
11 | #if defined(FL_PLATFORM_WINDOWS)
12 | void Init();
13 | #elif defined(FL_PLATFORM_ANDROID)
14 | void Init(void* env, void* mainView);
15 | #endif
16 |
17 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/String.cpp:
--------------------------------------------------------------------------------
1 | #include "String.h"
2 | #include "fl/Common.h"
3 |
4 | namespace fl {
5 |
6 | char* StringFormat::s_Buffer = new char[STRINGFORMAT_BUFFER_SIZE];
7 |
8 | std::vector SplitString(const String& string, const String& delimiters)
9 | {
10 | size_t start = 0;
11 | size_t end = string.find_first_of(delimiters);
12 |
13 | std::vector result;
14 |
15 | while (end <= String::npos)
16 | {
17 | String token = string.substr(start, end - start);
18 | if (!token.empty())
19 | result.push_back(token);
20 |
21 | if (end == String::npos)
22 | break;
23 |
24 | start = end + 1;
25 | end = string.find_first_of(delimiters, start);
26 | }
27 |
28 | return result;
29 | }
30 |
31 | std::vector SplitString(const String& string, const char delimiter)
32 | {
33 | return SplitString(string, String(1, delimiter));
34 | }
35 |
36 | std::vector Tokenize(const String& string)
37 | {
38 | return SplitString(string, " \t\n");
39 | }
40 |
41 | std::vector GetLines(const String& string)
42 | {
43 | return SplitString(string, "\n");
44 | }
45 |
46 | const char* FindToken(const char* str, const String& token)
47 | {
48 | const char* t = str;
49 | while (t = strstr(t, token.c_str()))
50 | {
51 | bool left = str == t || isspace(t[-1]);
52 | bool right = !t[token.size()] || isspace(t[token.size()]);
53 | if (left && right)
54 | return t;
55 |
56 | t += token.size();
57 | }
58 | return nullptr;
59 | }
60 |
61 | const char* FindToken(const String& string, const String& token)
62 | {
63 | return FindToken(string.c_str(), token);
64 | }
65 |
66 | int FindStringPosition(const String& string, const String& search, uint offset)
67 | {
68 | const char* str = string.c_str() + offset;
69 | const char* found = strstr(str, search.c_str());
70 | if (found == nullptr)
71 | return -1;
72 | return (int)(found - str) + offset;
73 | }
74 |
75 | String StringRange(const String& string, uint start, uint length)
76 | {
77 | return string.substr(start, length);
78 | }
79 |
80 | String RemoveStringRange(const String& string, uint start, uint length)
81 | {
82 | String result = string;
83 | return result.erase(start, length);
84 | }
85 |
86 | String GetBlock(const char* str, const char** outPosition)
87 | {
88 | const char* end = strstr(str, "}");
89 | if (!end)
90 | return String(str);
91 |
92 | if (outPosition)
93 | *outPosition = end;
94 | uint length = end - str + 1;
95 | return String(str, length);
96 | }
97 |
98 | String GetBlock(const String& string, uint offset)
99 | {
100 | const char* str = string.c_str() + offset;
101 | return GetBlock(str);
102 | }
103 |
104 | String GetStatement(const char* str, const char** outPosition)
105 | {
106 | const char* end = strstr(str, ";");
107 | if (!end)
108 | return String(str);
109 |
110 | if (outPosition)
111 | *outPosition = end;
112 | uint length = end - str + 1;
113 | return String(str, length);
114 | }
115 |
116 | bool StringContains(const String& string, const String& chars)
117 | {
118 | return string.find(chars) != String::npos;
119 | }
120 |
121 | bool StartsWith(const String& string, const String& start)
122 | {
123 | return string.find(start) == 0;
124 | }
125 |
126 | int NextInt(const String& string)
127 | {
128 | const char* str = string.c_str();
129 | for (uint i = 0; i < string.size(); i++)
130 | {
131 | if (isdigit(string[i]))
132 | return atoi(&string[i]);
133 | }
134 | return -1;
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/String.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/Types.h"
5 |
6 | #include
7 | typedef std::string String;
8 |
9 | namespace fl {
10 |
11 | #define STRINGFORMAT_BUFFER_SIZE 10 * 1024
12 |
13 | class FL_API StringFormat
14 | {
15 | private:
16 | static char* s_Buffer;
17 | public:
18 | template
19 | static String Hex(const T& input)
20 | {
21 | memset(s_Buffer, 0, STRINGFORMAT_BUFFER_SIZE);
22 | sprintf(s_Buffer, "%02x", input);
23 | return String(s_Buffer);
24 | }
25 |
26 | template
27 | static String Hex(const T* input, uint size)
28 | {
29 | memset(s_Buffer, 0, STRINGFORMAT_BUFFER_SIZE);
30 | for (uint i = 0; i < size; i++)
31 | sprintf(s_Buffer + i * 3, "%02x ", input[i]);
32 | return String(s_Buffer);
33 | }
34 |
35 | static String Float(const float input, uint places = 2)
36 | {
37 | memset(s_Buffer, 0, STRINGFORMAT_BUFFER_SIZE);
38 | sprintf(s_Buffer, "%.2f", input);
39 | return String(s_Buffer);
40 | }
41 |
42 | template
43 | static String ToString(const T& input)
44 | {
45 | return std::to_string(input);
46 | }
47 | };
48 |
49 | std::vector SplitString(const String& string, const String& delimiters);
50 | std::vector SplitString(const String& string, const char delimiter);
51 | std::vector Tokenize(const String& string);
52 | std::vector GetLines(const String& string);
53 |
54 | const char* FindToken(const char* str, const String& token);
55 | const char* FindToken(const String& string, const String& token);
56 | int FindStringPosition(const String& string, const String& search, uint offset = 0);
57 | String StringRange(const String& string, uint start, uint length);
58 | String RemoveStringRange(const String& string, uint start, uint length);
59 |
60 | String GetBlock(const char* str, const char** outPosition = nullptr);
61 | String GetBlock(const String& string, uint offset = 0);
62 |
63 | String GetStatement(const char* str, const char** outPosition = nullptr);
64 |
65 | bool StringContains(const String& string, const String& chars);
66 | bool StartsWith(const String& string, const String& start);
67 | int NextInt(const String& string);
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/Types.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | typedef unsigned char byte;
4 | typedef unsigned int uint;
5 | typedef unsigned short ushort;
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/gl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if defined(FL_PLATFORM_WINDOWS)
4 | #include
5 | #elif defined(FL_PLATFORM_ANDROID)
6 | #include
7 | #else
8 | #error No platform defined!
9 | #endif
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/Renderer.cpp:
--------------------------------------------------------------------------------
1 | #include "Renderer.h"
2 |
3 | #include
4 |
5 | #if defined(FL_PLATFORM_WINDOWS)
6 | #include
7 | #elif defined(FL_PLATFORM_ANDROID)
8 | #include
9 | #endif
10 |
11 | namespace fl {
12 |
13 | Renderer* Renderer::s_Instance = nullptr;
14 |
15 | Renderer::Renderer()
16 | {
17 | s_Instance = this;
18 | }
19 |
20 | void Renderer::Submit(RenderCommand* command)
21 | {
22 | m_CommandBuffer.push(command);
23 | }
24 |
25 | void Renderer::SetClearColor(float r, float g, float b, float a)
26 | {
27 | GLCall(glClearColor(r, g, b, a));
28 | }
29 |
30 | void Renderer::Clear()
31 | {
32 | GLCall(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
33 | }
34 |
35 | void Renderer::Flush()
36 | {
37 | while (!m_CommandBuffer.empty())
38 | {
39 | RenderCommand* command = m_CommandBuffer.front();
40 | FL_ASSERT(command);
41 | command->OnExecute();
42 | delete command;
43 | m_CommandBuffer.pop();
44 | }
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/Renderer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 |
5 | #include
6 |
7 | namespace fl {
8 |
9 | class FL_API RenderCommand
10 | {
11 | public:
12 | virtual void OnExecute() = 0;
13 | };
14 |
15 | class FL_API Renderer
16 | {
17 | private:
18 | static Renderer* s_Instance;
19 | private:
20 | std::queue m_CommandBuffer;
21 | public:
22 | Renderer();
23 | static void Init();
24 |
25 | void Submit(RenderCommand* command);
26 |
27 | void Clear();
28 | void SetClearColor(float r, float g, float b, float a);
29 | void Flush();
30 |
31 | inline static Renderer* GetInstance() { FL_ASSERT(s_Instance); return s_Instance; }
32 | };
33 |
34 | }
35 |
36 | #define SUBMIT_RENDER_0(x) class Command##__LINE__ : public RenderCommand { public: void OnExecute() override { x } }; fl::Renderer::GetInstance()->Submit(new Command ## __LINE__ ())
37 | #define SUBMIT_RENDER_1(param0Type, param0Name, x) class Command ## __LINE__ : public RenderCommand { private: param0Type param0; public: Command##__LINE__(param0Type& param0) : param0Name(param0) void OnExecute() override { x } }; fl::Renderer::GetInstance()->Submit(new Command ## __LINE__ (param0Name))
38 | #define SUBMIT_RENDER_2(param0Type, param0Name, param1Type, param1Name, x) class Command ## __LINE__ : public RenderCommand { private: param0Type param0; param1Type param1; public: Command ## __LINE__ (param0Type param0, param1Type param1) : param0(param0), param1(param1) {} void OnExecute() override { x } }; fl::Renderer::GetInstance()->Submit(new Command ## __LINE__ (param0Name, param1Name))
39 | #define SUBMIT_RENDER_3(param0Type, param0Name, param0Value, param1Type, param1Name, param1Value, param2Type, param2Name, param2Value, x) \
40 | class Command ## __LINE__ : public RenderCommand\
41 | {\
42 | private:\
43 | param0Type param0Name;\
44 | param1Type param1Name;\
45 | param2Type param2Name;\
46 | public:\
47 | Command ## __LINE__ (param0Type param0, param1Type param1, param2Type param2)\
48 | : param0Name(param0), param1Name(param1), param2Name(param2) {}\
49 | void OnExecute() override { x }\
50 | };\
51 | fl::Renderer::GetInstance()->Submit(new Command ## __LINE__ (param0Value, param1Value, param2Value))
52 |
53 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/Window.cpp:
--------------------------------------------------------------------------------
1 | #include "Window.h"
2 |
3 | #include
4 | #include "fl/system/Timer.h"
5 |
6 | namespace fl {
7 |
8 | static void GLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
9 | static void GLFWWindowSizeCallback(GLFWwindow* window, int width, int height);
10 | static void EmptyFunction() {}
11 | static void EmptyRenderFunction(Renderer&) {}
12 | static void EmptyKeyCallback(int, int) {}
13 |
14 | Window::Window(const String& title, uint width, uint height)
15 | : m_Title(title), m_Width(width), m_Height(height), m_FrameTime(0.0f)
16 | {
17 | m_OnUpdate = EmptyFunction;
18 | m_OnRender = EmptyRenderFunction;
19 | m_KeyCallback = EmptyKeyCallback;
20 |
21 | Init();
22 | }
23 |
24 | Window::~Window()
25 | {
26 | }
27 |
28 | void Window::Init()
29 | {
30 | glfwInit();
31 | m_GLFWWindow = glfwCreateWindow(m_Width, m_Height, m_Title.c_str(), NULL, NULL);
32 | GLFWwindow* window = m_GLFWWindow;
33 | glfwSetWindowUserPointer(window, this);
34 | glfwSetKeyCallback(window, GLFWKeyCallback);
35 | glfwSetWindowSizeCallback(window, GLFWWindowSizeCallback);
36 | glfwMakeContextCurrent(window);
37 | m_Renderer = new Renderer();
38 | Renderer::Init();
39 | }
40 |
41 | void Window::Show()
42 | {
43 | // m_GraphicsThread = std::thread(std::bind(&Window::GraphicsThread, this));
44 | GraphicsThread();
45 | }
46 |
47 | void Window::GraphicsThread()
48 | {
49 | GLFWwindow* window = m_GLFWWindow;
50 | float updateTimer = 0.0f;
51 | float updateTick = 1.0f / 60.0f;
52 | uint frames = 0;
53 | uint updates = 0;
54 | Timer timer;
55 | while (!glfwWindowShouldClose(window))
56 | {
57 | float now = timer.ElapsedMillis();
58 |
59 | Clear();
60 |
61 | if (now - updateTimer > updateTick)
62 | {
63 | m_OnUpdate();
64 | updates++;
65 | updateTimer += updateTick;
66 | }
67 |
68 | {
69 | Timer frametime;
70 | m_OnRender(*m_Renderer);
71 | frames++;
72 | m_FrameTime = frametime.ElapsedMillis();
73 | }
74 | glfwSwapBuffers(window);
75 | glfwPollEvents();
76 | }
77 | glfwTerminate();
78 | }
79 |
80 | void Window::Clear()
81 | {
82 | GLCall(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
83 | }
84 |
85 | static void GLFWKeyCallback(GLFWwindow* glfwWindow, int key, int scancode, int action, int mods)
86 | {
87 | Window* window = (Window*)glfwGetWindowUserPointer(glfwWindow);
88 | window->m_KeyCallback(key, action);
89 | if (action == GLFW_PRESS)
90 | window->m_PressedKeys.insert(key);
91 | else if (action == GLFW_RELEASE)
92 | window->m_PressedKeys.erase(key);
93 | }
94 |
95 | static void GLFWWindowSizeCallback(GLFWwindow* glfwWindow, int width, int height)
96 | {
97 | Window* window = (Window*)glfwGetWindowUserPointer(glfwWindow);
98 | window->m_Width = width;
99 | window->m_Height = height;
100 |
101 | GLCall(glViewport(0, 0, width, height));
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/Window.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/String.h"
5 | #include "Renderer.h"
6 |
7 | #include
8 | #include
9 |
10 | struct GLFWwindow;
11 |
12 | namespace fl {
13 |
14 | typedef std::function UpdateCallback;
15 | typedef std::function RenderCallback;
16 | typedef std::function KeyCallback;
17 |
18 | class FL_API Window
19 | {
20 | private:
21 | String m_Title;
22 | uint m_Width, m_Height;
23 | GLFWwindow* m_GLFWWindow;
24 | UpdateCallback m_OnUpdate;
25 | RenderCallback m_OnRender;
26 | KeyCallback m_KeyCallback;
27 | std::thread m_GraphicsThread;
28 | Renderer* m_Renderer;
29 | HashSet m_PressedKeys;
30 |
31 | float m_FrameTime;
32 | public:
33 | Window(const String& title, uint width, uint height);
34 | ~Window();
35 |
36 | void Init();
37 | void Show();
38 |
39 | inline void SetUpdateCallback(const UpdateCallback& callback) { m_OnUpdate = callback; }
40 | inline void SetRenderCallback(const RenderCallback& callback) { m_OnRender = callback; }
41 | inline void SetKeyCallback(const KeyCallback& callback) { m_KeyCallback = callback; }
42 | inline bool IsKeyPressed(int key) { return m_PressedKeys.find(key) != m_PressedKeys.end(); }
43 |
44 | inline float GetFrameTime() const { return m_FrameTime; }
45 | private:
46 | void GraphicsThread();
47 |
48 | void Clear();
49 |
50 | friend void GLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
51 | friend void GLFWWindowSizeCallback(GLFWwindow* window, int width, int height);
52 | };
53 |
54 | #define FL_KEY_RELEASED 0
55 | #define FL_KEY_PRESSED 1
56 | #define FL_KEY_REPEAT 2
57 |
58 | #define FL_KEY_SPACE 32
59 | #define FL_KEY_APOSTROPHE 39 /* ' */
60 | #define FL_KEY_COMMA 44 /* , */
61 | #define FL_KEY_MINUS 45 /* - */
62 | #define FL_KEY_PERIOD 46 /* . */
63 | #define FL_KEY_SLASH 47 /* / */
64 | #define FL_KEY_0 48
65 | #define FL_KEY_1 49
66 | #define FL_KEY_2 50
67 | #define FL_KEY_3 51
68 | #define FL_KEY_4 52
69 | #define FL_KEY_5 53
70 | #define FL_KEY_6 54
71 | #define FL_KEY_7 55
72 | #define FL_KEY_8 56
73 | #define FL_KEY_9 57
74 | #define FL_KEY_SEMICOLON 59 /* ; */
75 | #define FL_KEY_EQUAL 61 /* = */
76 | #define FL_KEY_A 65
77 | #define FL_KEY_B 66
78 | #define FL_KEY_C 67
79 | #define FL_KEY_D 68
80 | #define FL_KEY_E 69
81 | #define FL_KEY_F 70
82 | #define FL_KEY_G 71
83 | #define FL_KEY_H 72
84 | #define FL_KEY_I 73
85 | #define FL_KEY_J 74
86 | #define FL_KEY_K 75
87 | #define FL_KEY_L 76
88 | #define FL_KEY_M 77
89 | #define FL_KEY_N 78
90 | #define FL_KEY_O 79
91 | #define FL_KEY_P 80
92 | #define FL_KEY_Q 81
93 | #define FL_KEY_R 82
94 | #define FL_KEY_S 83
95 | #define FL_KEY_T 84
96 | #define FL_KEY_U 85
97 | #define FL_KEY_V 86
98 | #define FL_KEY_W 87
99 | #define FL_KEY_X 88
100 | #define FL_KEY_Y 89
101 | #define FL_KEY_Z 90
102 | #define FL_KEY_LEFT_BRACKET 91 /* [ */
103 | #define FL_KEY_BACKSLASH 92 /* \ */
104 | #define FL_KEY_RIGHT_BRACKET 93 /* ] */
105 | #define FL_KEY_GRAVE_ACCENT 96 /* ` */
106 | #define FL_KEY_WORLD_1 161 /* non-US #1 */
107 | #define FL_KEY_WORLD_2 162 /* non-US #2 */
108 |
109 | /* Function keys */
110 | #define FL_KEY_ESCAPE 256
111 | #define FL_KEY_ENTER 257
112 | #define FL_KEY_TAB 258
113 | #define FL_KEY_BACKSPACE 259
114 | #define FL_KEY_INSERT 260
115 | #define FL_KEY_DELETE 261
116 | #define FL_KEY_RIGHT 262
117 | #define FL_KEY_LEFT 263
118 | #define FL_KEY_DOWN 264
119 | #define FL_KEY_UP 265
120 | #define FL_KEY_PAGE_UP 266
121 | #define FL_KEY_PAGE_DOWN 267
122 | #define FL_KEY_HOME 268
123 | #define FL_KEY_END 269
124 | #define FL_KEY_CAPS_LOCK 280
125 | #define FL_KEY_SCROLL_LOCK 281
126 | #define FL_KEY_NUM_LOCK 282
127 | #define FL_KEY_PRINT_SCREEN 283
128 | #define FL_KEY_PAUSE 284
129 | #define FL_KEY_F1 290
130 | #define FL_KEY_F2 291
131 | #define FL_KEY_F3 292
132 | #define FL_KEY_F4 293
133 | #define FL_KEY_F5 294
134 | #define FL_KEY_F6 295
135 | #define FL_KEY_F7 296
136 | #define FL_KEY_F8 297
137 | #define FL_KEY_F9 298
138 | #define FL_KEY_F10 299
139 | #define FL_KEY_F11 300
140 | #define FL_KEY_F12 301
141 | #define FL_KEY_F13 302
142 | #define FL_KEY_F14 303
143 | #define FL_KEY_F15 304
144 | #define FL_KEY_F16 305
145 | #define FL_KEY_F17 306
146 | #define FL_KEY_F18 307
147 | #define FL_KEY_F19 308
148 | #define FL_KEY_F20 309
149 | #define FL_KEY_F21 310
150 | #define FL_KEY_F22 311
151 | #define FL_KEY_F23 312
152 | #define FL_KEY_F24 313
153 | #define FL_KEY_F25 314
154 | #define FL_KEY_KP_0 320
155 | #define FL_KEY_KP_1 321
156 | #define FL_KEY_KP_2 322
157 | #define FL_KEY_KP_3 323
158 | #define FL_KEY_KP_4 324
159 | #define FL_KEY_KP_5 325
160 | #define FL_KEY_KP_6 326
161 | #define FL_KEY_KP_7 327
162 | #define FL_KEY_KP_8 328
163 | #define FL_KEY_KP_9 329
164 | #define FL_KEY_KP_DECIMAL 330
165 | #define FL_KEY_KP_DIVIDE 331
166 | #define FL_KEY_KP_MULTIPLY 332
167 | #define FL_KEY_KP_SUBTRACT 333
168 | #define FL_KEY_KP_ADD 334
169 | #define FL_KEY_KP_ENTER 335
170 | #define FL_KEY_KP_EQUAL 336
171 | #define FL_KEY_LEFT_SHIFT 340
172 | #define FL_KEY_LEFT_CONTROL 341
173 | #define FL_KEY_LEFT_ALT 342
174 | #define FL_KEY_LEFT_SUPER 343
175 | #define FL_KEY_RIGHT_SHIFT 344
176 | #define FL_KEY_RIGHT_CONTROL 345
177 | #define FL_KEY_RIGHT_ALT 346
178 | #define FL_KEY_RIGHT_SUPER 347
179 | #define FL_KEY_MENU 348
180 |
181 | #define FL_KEY_LAST FL_KEY_MENU
182 |
183 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/Shader.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 |
5 | #include "fl/maths/maths.h"
6 |
7 | #include "ShaderUniform.h"
8 | #include "ShaderResource.h"
9 |
10 | namespace fl {
11 |
12 | #define SHADER_VERTEX_INDEX 0
13 | #define SHADER_UV_INDEX 1
14 | #define SHADER_MASK_UV_INDEX 2
15 | #define SHADER_TID_INDEX 3
16 | #define SHADER_MID_INDEX 4
17 | #define SHADER_COLOR_INDEX 5
18 |
19 | #define SHADER_UNIFORM_PROJECTION_MATRIX_NAME "sys_ProjectionMatrix"
20 | #define SHADER_UNIFORM_VIEW_MATRIX_NAME "sys_ViewMatrix"
21 | #define SHADER_UNIFORM_MODEL_MATRIX_NAME "sys_ModelMatrix"
22 |
23 | struct ShaderErrorInfo
24 | {
25 | uint shader;
26 | String message[2];
27 | uint line[2];
28 | };
29 |
30 | class FL_API Shader
31 | {
32 | public:
33 | static const Shader* s_CurrentlyBound;
34 | private:
35 | friend class Shader;
36 | friend class ShaderManager;
37 | private:
38 | uint m_Handle;
39 | String m_Name, m_Path;
40 | String m_Source;
41 | String m_VertexSource, m_FragmentSource;
42 |
43 | ShaderUniformBufferList m_VSUniformBuffers;
44 | ShaderUniformBufferList m_PSUniformBuffers;
45 | ShaderUniformBufferDeclaration* m_VSUserUniformBuffer;
46 | ShaderUniformBufferDeclaration* m_PSUserUniformBuffer;
47 | ShaderResourceList m_Resources;
48 | ShaderStructList m_Structs;
49 | public:
50 | Shader(const String& name, const String& source);
51 | ~Shader();
52 |
53 | void Init();
54 | void Shutdown();
55 | void Bind() const;
56 | void Unbind() const;
57 |
58 | void SetVSSystemUniformBuffer(byte* data, uint size, uint slot);
59 | void SetPSSystemUniformBuffer(byte* data, uint size, uint slot);
60 |
61 | void SetVSUserUniformBuffer(byte* data, uint size);
62 | void SetPSUserUniformBuffer(byte* data, uint size);
63 |
64 | void SetUniform(const String& name, byte* data);
65 | void ResolveAndSetUniformField(const ShaderUniformDeclaration& field, byte* data, int offset);
66 |
67 | inline const String& GetName() const { return m_Name; }
68 | inline const String& GetFilePath() const { return m_Path; }
69 |
70 | inline const ShaderUniformBufferList& GetVSSystemUniforms() const { return m_VSUniformBuffers; }
71 | inline const ShaderUniformBufferList& GetPSSystemUniforms() const { return m_PSUniformBuffers; }
72 | inline const ShaderUniformBufferDeclaration* GetVSUserUniformBuffer() const { return m_VSUserUniformBuffer; }
73 | inline const ShaderUniformBufferDeclaration* GetPSUserUniformBuffer() const { return m_PSUserUniformBuffer; }
74 | inline const ShaderResourceList& GetResources() const { return m_Resources; }
75 | private:
76 | static uint Compile(String** shaders, ShaderErrorInfo* info = nullptr);
77 | static void PreProcess(const String& source, String** shaders);
78 |
79 | void Parse(const String& vertexSource, const String& fragmentSource);
80 | void ParseUniform(const String& statement, uint shaderType);
81 | void ParseUniformStruct(const String& block, uint shaderType);
82 |
83 | bool IsTypeStringResource(const String& type);
84 |
85 | ShaderStruct* FindStruct(const String& name);
86 |
87 | void ResolveUniforms();
88 | void ValidateUniforms();
89 | bool IsSystemUniform(ShaderUniformDeclaration* uniform) const;
90 | int GetUniformLocation(const String& name);
91 |
92 | ShaderUniformDeclaration* FindUniformDeclaration(const String& name, const ShaderUniformBufferDeclaration* buffer);
93 | ShaderUniformDeclaration* FindUniformDeclaration(const String& name);
94 |
95 | void ResolveAndSetUniforms(ShaderUniformBufferDeclaration* buffer, byte* data, uint size);
96 | void ResolveAndSetUniform(ShaderUniformDeclaration* uniform, byte* data, uint size);
97 |
98 | void SetUniformStruct(ShaderUniformDeclaration* uniform, byte* data, int offset);
99 |
100 | void SetUniform1f(const String& name, float value);
101 | void SetUniform1fv(const String& name, float* value, int count);
102 | void SetUniform1i(const String& name, int value);
103 | void SetUniform1iv(const String& name, int* value, int count);
104 | void SetUniform2f(const String& name, const maths::vec2& vector);
105 | void SetUniform3f(const String& name, const maths::vec3& vector);
106 | void SetUniform4f(const String& name, const maths::vec4& vector);
107 | void SetUniformMat4(const String& name, const maths::mat4& matrix);
108 |
109 | void SetUniform1f(uint location, float value);
110 | void SetUniform1fv(uint location, float* value, int count);
111 | void SetUniform1i(uint location, int value);
112 | void SetUniform1iv(uint location, int* value, int count);
113 | void SetUniform2f(uint location, const maths::vec2& vector);
114 | void SetUniform3f(uint location, const maths::vec3& vector);
115 | void SetUniform4f(uint location, const maths::vec4& vector);
116 | void SetUniformMat4(uint location, const maths::mat4& matrix);
117 | public:
118 | static bool TryCompile(const String& source, String& error);
119 | static bool TryCompileFromFile(const String& filepath, String& error);
120 | public:
121 | static Shader* CreateFromFile(const String& name, const String& filepath, const void* address = nullptr); // TODO: Temp, implement properly
122 | static Shader* CreateFromSource(const String& name, const String& source);
123 | };
124 |
125 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderFactory.cpp:
--------------------------------------------------------------------------------
1 | #include "ShaderFactory.h"
2 |
3 | namespace fl { namespace ShaderFactory {
4 |
5 | static const char* s_SimpleShader =
6 | #if defined(FL_PLATFORM_WINDOWS)
7 | #include "default/Simple.shader"
8 | #elif defined(FL_PLATFORM_ANDROID)
9 | "#shader vertex\n"
10 | "#version 100\n"
11 | "\n"
12 | "precision highp float;\n"
13 | "\n"
14 | "attribute vec4 position;\n"
15 | "attribute vec2 uv;\n"
16 | "attribute vec2 mask_uv;\n"
17 | "\n"
18 | "uniform mat4 pr_matrix;\n"
19 | "\n"
20 | "varying vec2 var_UV;\n"
21 | "\n"
22 | "void main()\n"
23 | "{\n"
24 | " gl_Position = pr_matrix * position;\n"
25 | " var_UV = uv;\n"
26 | "}\n"
27 | "\n"
28 | "#shader fragment\n"
29 | "#version 100\n"
30 | "\n"
31 | "precision highp float;\n"
32 | "\n"
33 | "uniform sampler2D u_Texture;\n"
34 | "\n"
35 | "varying vec2 var_UV;\n"
36 | "\n"
37 | "void main()\n"
38 | "{\n"
39 | " gl_FragColor = texture2D(u_Texture, var_UV);\n"
40 | "}\n"
41 | #endif
42 | ;
43 |
44 | Shader* SimpleShader()
45 | {
46 | return Shader::CreateFromSource("Simple Shader", s_SimpleShader);
47 | }
48 |
49 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderFactory.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "Shader.h"
5 |
6 | namespace fl { namespace ShaderFactory {
7 |
8 | FL_API Shader* SimpleShader();
9 |
10 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderManager.cpp:
--------------------------------------------------------------------------------
1 | #include "ShaderManager.h"
2 |
3 | namespace fl {
4 |
5 | HashMap ShaderManager::s_Shaders;
6 |
7 | void ShaderManager::Add(Shader* shader)
8 | {
9 | s_Shaders[shader->m_Name] = shader;
10 | }
11 |
12 | Shader* ShaderManager::Get(const String& name)
13 | {
14 | if (s_Shaders.find(name) == s_Shaders.end())
15 | return nullptr;
16 |
17 | return s_Shaders[name];
18 | }
19 |
20 | void ShaderManager::Clean()
21 | {
22 | for (auto i : s_Shaders)
23 | delete i.second;
24 | }
25 |
26 | void ShaderManager::Reload(const String& name)
27 | {
28 | if (s_Shaders.find(name) == s_Shaders.end())
29 | {
30 | std::cout << "Could not find '" << name << "' shader to reload." << std::endl;
31 | return;
32 | }
33 |
34 | Shader*& shader = s_Shaders[name];
35 | String path = shader->GetFilePath();
36 | String error;
37 | if (!Shader::TryCompileFromFile(path, error))
38 | {
39 | std::cout << error << std::endl;
40 | }
41 | else
42 | {
43 | shader->~Shader();
44 | shader = Shader::CreateFromFile(name, path, shader);
45 | std::cout << "Reloaded shader: " << name << std::endl;
46 | }
47 | }
48 |
49 | void ShaderManager::Reload(const Shader* shader)
50 | {
51 | String name = shader->GetName();
52 | String path = shader->GetFilePath();
53 | shader->~Shader();
54 | Shader::CreateFromFile(name, path, shader);
55 | }
56 |
57 |
58 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderManager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/Types.h"
5 |
6 | #include "Shader.h"
7 |
8 | namespace fl {
9 |
10 | class FL_API ShaderManager
11 | {
12 | private:
13 | static HashMap s_Shaders;
14 | public:
15 | static void Add(Shader* shader);
16 | static Shader* Get(const String& name);
17 | static void Clean();
18 |
19 | static void Reload(const String& name);
20 | static void Reload(const Shader* shader);
21 | private:
22 | ShaderManager() { }
23 | };
24 |
25 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderResource.cpp:
--------------------------------------------------------------------------------
1 | #include "ShaderResource.h"
2 |
3 | namespace fl {
4 |
5 | ShaderResourceDeclaration::ShaderResourceDeclaration(Type type, const String& name, uint count)
6 | : m_Type(type), m_Name(name), m_Count(count)
7 | {
8 | m_Name = name;
9 | m_Count = count;
10 | }
11 |
12 | ShaderResourceDeclaration::Type ShaderResourceDeclaration::StringToType(const String& type)
13 | {
14 | if (type == "sampler2D") return ShaderResourceDeclaration::Type::TEXTURE2D;
15 | if (type == "samplerCube") return ShaderResourceDeclaration::Type::TEXTURECUBE;
16 | if (type == "samplerShadow") return ShaderResourceDeclaration::Type::TEXTURESHADOW;
17 |
18 | return Type::NONE;
19 | }
20 |
21 | String ShaderResourceDeclaration::TypeToString(Type type)
22 | {
23 | switch (type)
24 | {
25 | case Type::TEXTURE2D: return "sampler2D";
26 | case Type::TEXTURECUBE: return "samplerCube";
27 | case Type::TEXTURESHADOW: return "samplerShadow";
28 | }
29 | return "Invalid Type";
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderResource.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/String.h"
5 |
6 | namespace fl {
7 |
8 | class ShaderResourceDeclaration
9 | {
10 | public:
11 | enum class Type
12 | {
13 | NONE, TEXTURE2D, TEXTURECUBE, TEXTURESHADOW
14 | };
15 | private:
16 | friend class Shader;
17 | private:
18 | String m_Name;
19 | uint m_Register;
20 | uint m_Count;
21 | Type m_Type;
22 | public:
23 | ShaderResourceDeclaration(Type type, const String& name, uint count);
24 |
25 | inline const String& GetName() const { return m_Name; }
26 | inline uint GetRegister() const { return m_Register; }
27 | inline uint GetCount() const { return m_Count; }
28 |
29 | inline Type GetType() const { return m_Type; }
30 | public:
31 | static Type StringToType(const String& type);
32 | static String TypeToString(Type type);
33 | };
34 |
35 | typedef std::vector ShaderResourceList;
36 |
37 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderUniform.cpp:
--------------------------------------------------------------------------------
1 | #include "ShaderUniform.h"
2 |
3 | #include "Shader.h"
4 |
5 | namespace fl {
6 |
7 | void ShaderStruct::AddField(ShaderUniformDeclaration* field)
8 | {
9 | m_Size += field->GetSize();
10 | uint offset = 0;
11 | if (m_Fields.size())
12 | {
13 | ShaderUniformDeclaration* previous = m_Fields.back();
14 | offset = previous->GetOffset() + previous->GetSize();
15 | }
16 | field->SetOffset(offset);
17 | m_Fields.push_back(field);
18 | }
19 |
20 |
21 | ShaderUniformDeclaration::ShaderUniformDeclaration(Type type, const String& name, uint count)
22 | : m_Type(type), m_Struct(nullptr)
23 | {
24 | m_Name = name;
25 | m_Count = count;
26 | m_Size = SizeOfUniformType(type) * count;
27 | }
28 |
29 | ShaderUniformDeclaration::ShaderUniformDeclaration(ShaderStruct* uniformStruct, const String& name, uint count)
30 | : m_Struct(uniformStruct), m_Type(ShaderUniformDeclaration::Type::STRUCT)
31 | {
32 | m_Name = name;
33 | m_Count = count;
34 | m_Size = m_Struct->GetSize() * count;
35 | }
36 |
37 | void ShaderUniformDeclaration::SetOffset(uint offset)
38 | {
39 | if (m_Type == ShaderUniformDeclaration::Type::STRUCT)
40 | m_Struct->SetOffset(offset);
41 |
42 | m_Offset = offset;
43 | }
44 |
45 | uint ShaderUniformDeclaration::SizeOfUniformType(Type type)
46 | {
47 | switch (type)
48 | {
49 | case ShaderUniformDeclaration::Type::INT32: return 4;
50 | case ShaderUniformDeclaration::Type::FLOAT32: return 4;
51 | case ShaderUniformDeclaration::Type::VEC2: return 4 * 2;
52 | case ShaderUniformDeclaration::Type::VEC3: return 4 * 3;
53 | case ShaderUniformDeclaration::Type::VEC4: return 4 * 4;
54 | case ShaderUniformDeclaration::Type::MAT3: return 4 * 3 * 3;
55 | case ShaderUniformDeclaration::Type::MAT4: return 4 * 4 * 4;
56 | }
57 | return 0;
58 | }
59 |
60 | ShaderUniformDeclaration::Type ShaderUniformDeclaration::StringToType(const String& type)
61 | {
62 | if (type == "int32") return Type::INT32;
63 | if (type == "float") return Type::FLOAT32;
64 | if (type == "vec2") return Type::VEC2;
65 | if (type == "vec3") return Type::VEC3;
66 | if (type == "vec4") return Type::VEC4;
67 | if (type == "mat3") return Type::MAT3;
68 | if (type == "mat4") return Type::MAT4;
69 |
70 | return Type::NONE;
71 | }
72 |
73 | String ShaderUniformDeclaration::TypeToString(Type type)
74 | {
75 | switch (type)
76 | {
77 | case ShaderUniformDeclaration::Type::INT32: return "int32";
78 | case ShaderUniformDeclaration::Type::FLOAT32: return "float";
79 | case ShaderUniformDeclaration::Type::VEC2: return "vec2";
80 | case ShaderUniformDeclaration::Type::VEC3: return "vec3";
81 | case ShaderUniformDeclaration::Type::VEC4: return "vec4";
82 | case ShaderUniformDeclaration::Type::MAT3: return "mat3";
83 | case ShaderUniformDeclaration::Type::MAT4: return "mat4";
84 | }
85 | return "Invalid Type";
86 | }
87 |
88 | ShaderUniformBufferDeclaration::ShaderUniformBufferDeclaration(const String& name, uint shaderType)
89 | : m_Name(name), m_ShaderType(shaderType), m_Size(0), m_Register(0)
90 | {
91 | }
92 |
93 | void ShaderUniformBufferDeclaration::PushUniform(ShaderUniformDeclaration* uniform)
94 | {
95 | uint offset = 0;
96 | if (m_Uniforms.size())
97 | {
98 | ShaderUniformDeclaration* previous = (ShaderUniformDeclaration*)m_Uniforms.back();
99 | offset = previous->m_Offset + previous->m_Size;
100 | }
101 | uniform->SetOffset(offset);
102 | m_Size += uniform->GetSize();
103 | m_Uniforms.push_back(uniform);
104 | }
105 |
106 | ShaderUniformDeclaration* ShaderUniformBufferDeclaration::FindUniform(const String& name)
107 | {
108 | for (ShaderUniformDeclaration* uniform : m_Uniforms)
109 | {
110 | if (uniform->GetName() == name)
111 | return uniform;
112 | }
113 | return nullptr;
114 | }
115 |
116 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/ShaderUniform.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/String.h"
5 |
6 | #include
7 | #include
8 |
9 | namespace fl {
10 |
11 | class ShaderUniformDeclaration;
12 |
13 | class FL_API ShaderStruct
14 | {
15 | private:
16 | friend class Shader;
17 | private:
18 | String m_Name;
19 | std::vector m_Fields;
20 | uint m_Size;
21 | uint m_Offset;
22 | public:
23 | ShaderStruct(const String& name)
24 | : m_Name(name), m_Size(0), m_Offset(0)
25 | {
26 | }
27 |
28 | void AddField(ShaderUniformDeclaration* field);
29 |
30 | inline void SetOffset(uint offset) { m_Offset = offset; }
31 |
32 | inline const String& GetName() const { return m_Name; }
33 | inline uint GetSize() const { return m_Size; }
34 | inline uint GetOffset() const { return m_Offset; }
35 | inline const std::vector& GetFields() const { return m_Fields; }
36 | };
37 |
38 | typedef std::vector ShaderStructList;
39 |
40 | class FL_API ShaderUniformDeclaration
41 | {
42 | private:
43 | friend class Shader;
44 | friend class ShaderStruct;
45 | friend class ShaderUniformBufferDeclaration;
46 | public:
47 | enum class Type
48 | {
49 | NONE, FLOAT32, VEC2, VEC3, VEC4, MAT3, MAT4, INT32, STRUCT
50 | };
51 | private:
52 | String m_Name;
53 | uint m_Size;
54 | uint m_Count;
55 | uint m_Offset;
56 |
57 | Type m_Type;
58 | ShaderStruct* m_Struct;
59 | mutable int m_Location;
60 | public:
61 | ShaderUniformDeclaration(Type type, const String& name, uint count = 1);
62 | ShaderUniformDeclaration(ShaderStruct* uniformStruct, const String& name, uint count = 1);
63 |
64 | inline const String& GetName() const { return m_Name; }
65 | inline uint GetSize() const { return m_Size; }
66 | inline uint GetCount() const { return m_Count; }
67 | inline uint GetOffset() const { return m_Offset; }
68 | inline uint GetAbsoluteOffset() const { return m_Struct ? m_Struct->GetOffset() + m_Offset : m_Offset; }
69 |
70 | int GetLocation() const { return m_Location; }
71 | inline Type GetType() const { return m_Type; }
72 | inline const ShaderStruct& GetShaderUniformStruct() const { FL_ASSERT(m_Struct); return *m_Struct; }
73 | protected:
74 | void SetOffset(uint offset);
75 | public:
76 | static uint SizeOfUniformType(Type type);
77 | static Type StringToType(const String& type);
78 | static String TypeToString(Type type);
79 | };
80 |
81 | typedef std::vector ShaderUniformList;
82 |
83 | struct FL_API ShaderUniformField
84 | {
85 | ShaderUniformDeclaration::Type type;
86 | String name;
87 | uint count;
88 | mutable uint size;
89 | mutable int location;
90 | };
91 |
92 | // TODO: Eventually support OpenGL uniform buffers. This is more platform-side.
93 | class FL_API ShaderUniformBufferDeclaration
94 | {
95 | private:
96 | friend class Shader;
97 | private:
98 | String m_Name;
99 | ShaderUniformList m_Uniforms;
100 | uint m_Register;
101 | uint m_Size;
102 | uint m_ShaderType; // 0 = VS, 1 = PS
103 | public:
104 | ShaderUniformBufferDeclaration(const String& name, uint shaderType);
105 |
106 | void PushUniform(ShaderUniformDeclaration* uniform);
107 |
108 | inline const String& GetName() const { return m_Name; }
109 | inline uint GetRegister() const { return m_Register; }
110 | inline uint GetShaderType() const { return m_ShaderType; }
111 | inline uint GetSize() const { return m_Size; }
112 | inline const ShaderUniformList& GetUniformDeclarations() const { return m_Uniforms; }
113 |
114 | ShaderUniformDeclaration* FindUniform(const String& name);
115 | };
116 |
117 | typedef std::vector ShaderUniformBufferList;
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/graphics/shaders/default/Simple.shader:
--------------------------------------------------------------------------------
1 | R"(
2 | #shader vertex
3 | #version 330 core
4 |
5 | layout (location = 0) in vec4 position;
6 | layout (location = 1) in vec2 uv;
7 | layout (location = 2) in vec2 mask_uv;
8 | layout (location = 3) in float tid;
9 | layout (location = 4) in float mid;
10 | layout (location = 5) in vec4 color;
11 |
12 | uniform mat4 pr_matrix;
13 |
14 | out DATA
15 | {
16 | vec2 uv;
17 | } vs_out;
18 |
19 | void main()
20 | {
21 | gl_Position = pr_matrix * position;
22 | vs_out.uv = uv;
23 | };
24 |
25 | #shader fragment
26 | #version 330 core
27 |
28 | layout (location = 0) out vec4 color;
29 |
30 | uniform sampler2D u_Texture;
31 |
32 | in DATA
33 | {
34 | vec2 uv;
35 | } fs_in;
36 |
37 | void main()
38 | {
39 | color = texture(u_Texture, fs_in.uv);
40 | };
41 | )"
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/AABB.cpp:
--------------------------------------------------------------------------------
1 | #include "AABB.h"
2 |
3 | #include "Rectangle.h"
4 | #include "mat4.h"
5 |
6 | namespace fl { namespace maths {
7 |
8 | AABB::AABB()
9 | : min(vec3()), max(vec3())
10 | {
11 | }
12 |
13 | AABB::AABB(const Rectangle& rectangle)
14 | : min(rectangle.GetMinimumBound()), max(rectangle.GetMaximumBound())
15 | {
16 | }
17 |
18 | AABB::AABB(const vec2& min, const vec2& max)
19 | : min(vec3(min)), max(vec3(max))
20 | {
21 | }
22 |
23 | AABB::AABB(const vec3& min, const vec3& max)
24 | : min(min), max(max)
25 | {
26 | }
27 |
28 | AABB::AABB(float x, float y, float width, float height)
29 | : min(vec3(x, y, 0.0f)), max(vec3(width, height, 0.0f))
30 | {
31 | }
32 |
33 | AABB::AABB(float x, float y, float z, float width, float height, float depth)
34 | : min(vec3(x, y, z)), max(vec3(width, height, depth))
35 | {
36 | }
37 |
38 | bool AABB::Intersects(const AABB& other) const
39 | {
40 | return (max > other.min && min < other.max) || (min > other.max && max < other.min);
41 | }
42 |
43 | bool AABB::Contains(const vec2& point) const
44 | {
45 | return vec3(point) > min && vec3(point) < max;
46 | }
47 |
48 | bool AABB::Contains(const vec3& point) const
49 | {
50 | return point > min && point < max;
51 | }
52 |
53 | AABB AABB::GetTransformed(const mat4& transform) const
54 | {
55 | return AABB(transform.Multiply(min), transform.Multiply(max));
56 | }
57 |
58 | vec3 AABB::Center() const
59 | {
60 | return (max + min) * 0.5f;
61 | }
62 |
63 | bool AABB::operator==(const AABB& other) const
64 | {
65 | return min == other.min && max == other.max;
66 | }
67 |
68 | bool AABB::operator!=(const AABB& other) const
69 | {
70 | return !(*this == other);
71 | }
72 |
73 | bool AABB::operator<(const AABB& other) const
74 | {
75 | return max < other.min;
76 | }
77 |
78 | bool AABB::operator>(const AABB& other) const
79 | {
80 | return min > other.max;
81 | }
82 |
83 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/AABB.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "fl/Common.h"
5 |
6 | #include "vec2.h"
7 | #include "vec3.h"
8 |
9 | namespace fl { namespace maths {
10 |
11 | struct Rectangle;
12 |
13 | struct FL_API AABB
14 | {
15 | vec3 min;
16 | vec3 max;
17 |
18 | AABB();
19 | AABB(const Rectangle& rectangle);
20 | AABB(const vec2& min, const vec2& max);
21 | AABB(const vec3& min, const vec3& max);
22 | AABB(float x, float y, float width, float height);
23 | AABB(float x, float y, float z, float width, float height, float depth);
24 |
25 | bool Intersects(const AABB& other) const;
26 | bool Contains(const vec2& point) const;
27 | bool Contains(const vec3& point) const;
28 |
29 | AABB GetTransformed(const mat4& transform) const;
30 |
31 | vec3 Center() const;
32 |
33 | bool operator==(const AABB& other) const;
34 | bool operator!=(const AABB& other) const;
35 |
36 | bool operator<(const AABB& other) const;
37 | bool operator>(const AABB& other) const;
38 |
39 | friend std::ostream& operator<<(std::ostream& stream, const AABB& aabb);
40 |
41 | inline vec3 GetSize() const { return vec3(abs(max.x - min.x), abs(max.y - min.y), abs(max.z - min.z)); }
42 | };
43 |
44 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/Quaternion.cpp:
--------------------------------------------------------------------------------
1 | #include "Quaternion.h"
2 |
3 | namespace fl { namespace maths {
4 |
5 | #define _VECTORMATH_SLERP_TOL 0.999f
6 |
7 | Quaternion::Quaternion()
8 | : x(0), y(0), z(0), w(1)
9 | {
10 | }
11 |
12 | Quaternion::Quaternion(const Quaternion& Quaternion)
13 | {
14 | x = Quaternion.x;
15 | y = Quaternion.y;
16 | z = Quaternion.z;
17 | w = Quaternion.w;
18 | }
19 |
20 | Quaternion::Quaternion(float x, float y, float z, float w)
21 | : x(x), y(y), z(z), w(w)
22 | {
23 | }
24 |
25 | Quaternion::Quaternion(const vec4& vec)
26 | {
27 | x = vec.x;
28 | y = vec.y;
29 | z = vec.z;
30 | w = vec.w;
31 | }
32 |
33 | Quaternion::Quaternion(float scalar)
34 | {
35 | x = scalar;
36 | y = scalar;
37 | z = scalar;
38 | w = scalar;
39 | }
40 |
41 | Quaternion::Quaternion(const vec3& xyz, float w)
42 | {
43 | this->SetXYZ(xyz);
44 | this->w = w;
45 | }
46 |
47 | Quaternion Quaternion::Identity()
48 | {
49 | return Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
50 | }
51 |
52 | Quaternion Quaternion::FromEulerAngles(const vec3& angles)
53 | {
54 | Quaternion pitch(vec3(1.0, 0.0, 0.0), angles.x);
55 | Quaternion yaw(vec3(0.0, 1.0, 0.0), angles.y);
56 | Quaternion roll(vec3(0.0, 0.0, 1.0), angles.z);
57 | return pitch * yaw * roll;
58 | }
59 |
60 | Quaternion& Quaternion::operator =(const Quaternion & Quaternion)
61 | {
62 | x = Quaternion.x;
63 | y = Quaternion.y;
64 | z = Quaternion.z;
65 | w = Quaternion.w;
66 | return *this;
67 | }
68 |
69 | Quaternion& Quaternion::SetXYZ(const vec3 & vec)
70 | {
71 | x = vec.x;
72 | y = vec.y;
73 | z = vec.z;
74 | return *this;
75 | }
76 |
77 | const vec3 Quaternion::GetXYZ() const
78 | {
79 | return vec3(x, y, z);
80 | }
81 |
82 | Quaternion& Quaternion::SetElem(int idx, float value)
83 | {
84 | *(&x + idx) = value;
85 | return *this;
86 | }
87 |
88 | float Quaternion::GetElem(int idx) const
89 | {
90 | return *(&x + idx);
91 | }
92 |
93 | float Quaternion::operator [](int idx) const
94 | {
95 | return *(&x + idx);
96 | }
97 |
98 | vec3 Quaternion::GetAxis() const
99 | {
100 | float x = 1.0f - w * w;
101 | if (x < 0.0000001f) // Divide by zero safety check
102 | return vec3::XAxis();
103 |
104 | float x2 = x * x;
105 | return GetXYZ() / x2;
106 | }
107 |
108 | vec3 Quaternion::ToEulerAngles() const
109 | {
110 | return vec3(atan2(2 * x * w - 2 * y * z, 1 - 2 * x * x - 2 * z * z),
111 | atan2(2 * y * w - 2 * x * z, 1 - 2 * y * y - 2 * z * z),
112 | asin(2 * x * y + 2 * z * w));
113 | }
114 |
115 | const Quaternion Quaternion::operator+(const Quaternion& quaternion) const
116 | {
117 | return Quaternion(x + quaternion.x, y + quaternion.y, z + quaternion.z, w + quaternion.w);
118 | }
119 |
120 | const Quaternion Quaternion::operator-(const Quaternion& quaternion) const
121 | {
122 | return Quaternion(x - quaternion.x, y - quaternion.y, z - quaternion.z, w - quaternion.w);
123 | }
124 |
125 | const Quaternion Quaternion::operator*(float scalar) const
126 | {
127 | return Quaternion(x * scalar, y * scalar, z * scalar, w * scalar);
128 | }
129 |
130 | const Quaternion Quaternion::operator/(float scalar) const
131 | {
132 | return Quaternion(x / scalar, y / scalar, z / scalar, w / scalar);
133 | }
134 |
135 | const Quaternion Quaternion::operator-() const
136 | {
137 | return Quaternion(-x, -y, -z, -w);
138 | }
139 |
140 | bool Quaternion::operator ==(const Quaternion & Quaternion) const
141 | {
142 | return (x == Quaternion.x) && (y == Quaternion.y) && (z == Quaternion.z) && (w == Quaternion.w);
143 | }
144 |
145 | bool Quaternion::operator !=(const Quaternion & Quaternion) const
146 | {
147 | return !(*this == Quaternion);
148 | }
149 |
150 | float Norm(const Quaternion& quaternion)
151 | {
152 | float result;
153 | result = (quaternion.x * quaternion.x);
154 | result = (result + (quaternion.y * quaternion.y));
155 | result = (result + (quaternion.z * quaternion.z));
156 | result = (result + (quaternion.w * quaternion.w));
157 | return result;
158 | }
159 |
160 | float Length(const Quaternion& quaternion)
161 | {
162 | return sqrt(Norm(quaternion));
163 | }
164 |
165 | const Quaternion Normalize(const Quaternion& quaternion)
166 | {
167 | float lenSqr, lenInv;
168 | lenSqr = Norm(quaternion);
169 | lenInv = rsqrt(lenSqr);
170 | return quaternion * lenInv;
171 | }
172 |
173 | const Quaternion NormalizeEst(const Quaternion& quaternion)
174 | {
175 | float lenSqr, lenInv;
176 | lenSqr = Norm(quaternion);
177 | lenInv = rsqrt(lenSqr);
178 | return quaternion * lenInv;
179 | }
180 |
181 | const Quaternion Quaternion::Rotation(const vec3& unitVec0, const vec3& unitVec1)
182 | {
183 | float cosHalfAngleX2, recipCosHalfAngleX2;
184 | cosHalfAngleX2 = sqrt((2.0f * (1.0f + unitVec0.Dot(unitVec1))));
185 | recipCosHalfAngleX2 = (1.0f / cosHalfAngleX2);
186 | return Quaternion((unitVec0.Cross(unitVec1) * recipCosHalfAngleX2), (cosHalfAngleX2 * 0.5f));
187 | }
188 |
189 | const Quaternion Quaternion::Rotation(float radians, const vec3 & unitVec)
190 | {
191 | float angle = radians * 0.5f;
192 | return Quaternion((unitVec * sin(angle)), cos(angle));
193 | }
194 |
195 | const Quaternion Quaternion::operator*(const Quaternion& quat) const
196 | {
197 | return Normalize(Quaternion(
198 | (((w * quat.x) + (x * quat.w)) + (y * quat.z)) - (z * quat.y),
199 | (((w * quat.y) + (y * quat.w)) + (z * quat.x)) - (x * quat.z),
200 | (((w * quat.z) + (z * quat.w)) + (x * quat.y)) - (y * quat.x),
201 | (((w * quat.w) - (x * quat.x)) - (y * quat.y)) - (z * quat.z)
202 | ));
203 | }
204 |
205 | vec3 Quaternion::Rotate(const Quaternion& quat, const vec3& vec)
206 | {
207 | float tmpX, tmpY, tmpZ, tmpW;
208 | tmpX = (((quat.w * vec.x) + (quat.y * vec.z)) - (quat.z * vec.y));
209 | tmpY = (((quat.w * vec.y) + (quat.z * vec.x)) - (quat.x * vec.z));
210 | tmpZ = (((quat.w * vec.z) + (quat.x * vec.y)) - (quat.y * vec.x));
211 | tmpW = (((quat.x * vec.x) + (quat.y * vec.y)) + (quat.z * vec.z));
212 | return vec3(
213 | ((((tmpW * quat.x) + (tmpX * quat.w)) - (tmpY * quat.z)) + (tmpZ * quat.y)),
214 | ((((tmpW * quat.y) + (tmpY * quat.w)) - (tmpZ * quat.x)) + (tmpX * quat.z)),
215 | ((((tmpW * quat.z) + (tmpZ * quat.w)) - (tmpX * quat.y)) + (tmpY * quat.x))
216 | );
217 | }
218 |
219 | Quaternion Quaternion::Conjugate() const
220 | {
221 | return Quaternion(-x, -y, -z, w);
222 | }
223 |
224 | const Quaternion Select(const Quaternion& quat0, const Quaternion& quat1, bool select1)
225 | {
226 | return Quaternion(select1 ? quat1.x : quat0.x, select1 ? quat1.y : quat0.y, select1 ? quat1.z : quat0.z, select1 ? quat1.w : quat0.w);
227 | }
228 |
229 | float Quaternion::Dot(const Quaternion& other) const
230 | {
231 | float result = (x * other.x);
232 | result = (result + (y * other.y));
233 | result = (result + (z * other.z));
234 | result = (result + (w * other.w));
235 | return result;
236 | }
237 |
238 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/Quaternion.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 |
5 | #include "mat4.h"
6 |
7 | namespace fl { namespace maths {
8 |
9 | struct FL_API Quaternion
10 | {
11 | float x, y, z, w;
12 |
13 | Quaternion();
14 | Quaternion(const Quaternion& quaternion);
15 | Quaternion(float x, float y, float z, float w);
16 | Quaternion(const vec3& xyz, float w);
17 | Quaternion(const vec4& vec);
18 | Quaternion(float scalar);
19 |
20 | Quaternion& operator=(const Quaternion& quat);
21 |
22 | Quaternion& SetXYZ(const vec3& vec);
23 | const vec3 GetXYZ() const;
24 |
25 | Quaternion& SetElem(int idx, float value);
26 | float GetElem(int idx) const;
27 | vec3 GetAxis() const;
28 | vec3 ToEulerAngles() const;
29 |
30 | const Quaternion operator+(const Quaternion& Quaternion) const;
31 | const Quaternion operator-(const Quaternion& Quaternion) const;
32 | const Quaternion operator*(const Quaternion& Quaternion) const;
33 | const Quaternion operator*(float scalar) const;
34 | const Quaternion operator/(float scalar) const;
35 | float operator[](int idx) const;
36 |
37 | Quaternion& operator+=(const Quaternion& Quaternion)
38 | {
39 | *this = *this + Quaternion;
40 | return *this;
41 | }
42 |
43 | Quaternion& operator-=(const Quaternion& Quaternion)
44 | {
45 | *this = *this - Quaternion;
46 | return *this;
47 | }
48 |
49 | Quaternion& operator*=(const Quaternion& Quaternion)
50 | {
51 | *this = *this * Quaternion;
52 | return *this;
53 | }
54 |
55 | Quaternion& operator*=(float scalar)
56 | {
57 | *this = *this * scalar;
58 | return *this;
59 | }
60 |
61 | Quaternion& operator/=(float scalar)
62 | {
63 | *this = *this / scalar;
64 | return *this;
65 | }
66 |
67 | const Quaternion operator-() const;
68 | bool operator==(const Quaternion& quaternion) const;
69 | bool operator!=(const Quaternion& quaternion) const;
70 | static Quaternion Identity();
71 | static Quaternion FromEulerAngles(const vec3& angles);
72 |
73 | static vec3 Rotate(const Quaternion & quat, const vec3 & vec);
74 |
75 | static const Quaternion Rotation(const vec3& unitVec0, const vec3& unitVec1);
76 | static const Quaternion Rotation(float radians, const vec3& unitVec);
77 |
78 | static const Quaternion RotationX(float radians)
79 | {
80 | float angle = radians * 0.5f;
81 | return Quaternion(sin(angle), 0.0f, 0.0f, cos(angle));
82 | }
83 |
84 | static const Quaternion RotationY(float radians)
85 | {
86 | float angle = radians * 0.5f;
87 | return Quaternion(0.0f, sin(angle), 0.0f, cos(angle));
88 | }
89 |
90 | static const Quaternion RotationZ(float radians)
91 | {
92 | float angle = radians * 0.5f;
93 | return Quaternion(0.0f, 0.0f, sin(angle), cos(angle));
94 | }
95 |
96 | float Dot(const Quaternion& other) const;
97 | Quaternion Conjugate() const;
98 |
99 | };
100 |
101 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/Rectangle.cpp:
--------------------------------------------------------------------------------
1 | #include "Rectangle.h"
2 |
3 | #include "AABB.h"
4 |
5 | namespace fl { namespace maths {
6 |
7 | Rectangle::Rectangle()
8 | : position(vec2()), size(vec2())
9 | {
10 | }
11 |
12 | Rectangle::Rectangle(const AABB& aabb)
13 | : position(vec2(aabb.min)), size(vec2(aabb.GetSize()))
14 | {
15 | }
16 |
17 | Rectangle::Rectangle(const vec2& position, const vec2& size)
18 | : position(position), size(size)
19 | {
20 | }
21 |
22 | Rectangle::Rectangle(float x, float y, float width, float height)
23 | : position(vec2(x, y)), size(vec2(width, height))
24 | {
25 | }
26 |
27 | bool Rectangle::Intersects(const Rectangle& other) const
28 | {
29 | return (size > other.position && position < other.size) || (position > other.size && size < other.position);
30 | }
31 |
32 | bool Rectangle::Contains(const vec2& point) const
33 | {
34 | return point > GetMinimumBound() && point < GetMaximumBound();
35 | }
36 |
37 | bool Rectangle::Contains(const vec3& point) const
38 | {
39 | return Contains(vec2(point));
40 | }
41 |
42 | bool Rectangle::operator==(const Rectangle& other) const
43 | {
44 | return position == other.position && size == other.size;
45 | }
46 |
47 | bool Rectangle::operator!=(const Rectangle& other) const
48 | {
49 | return !(*this == other);
50 | }
51 |
52 | bool Rectangle::operator<(const Rectangle& other) const
53 | {
54 | return size < other.size;
55 | }
56 |
57 | bool Rectangle::operator>(const Rectangle& other) const
58 | {
59 | return size > other.size;
60 | }
61 |
62 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/Rectangle.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 |
5 | #include "vec2.h"
6 | #include "vec3.h"
7 |
8 | namespace fl { namespace maths {
9 |
10 | struct AABB;
11 |
12 | ///
13 | /// Rectangle
14 | ///
15 | /// Note that position is stored as a center point, and size is
16 | /// half-width and half-height extents.
17 | struct FL_API Rectangle
18 | {
19 | union
20 | {
21 | vec2 position;
22 | struct
23 | {
24 | float x;
25 | float y;
26 | };
27 | };
28 | union
29 | {
30 | vec2 size;
31 | struct
32 | {
33 | float width;
34 | float height;
35 | };
36 | };
37 |
38 | Rectangle();
39 | Rectangle(const AABB& aabb);
40 | Rectangle(const vec2& position, const vec2& size);
41 | Rectangle(float x, float y, float width, float height);
42 |
43 | bool Intersects(const Rectangle& other) const;
44 | bool Contains(const vec2& point) const;
45 | bool Contains(const vec3& point) const;
46 |
47 | inline vec2 GetMinimumBound() const { return position - size; }
48 | inline vec2 GetMaximumBound() const { return position + size; }
49 |
50 | bool operator==(const Rectangle& other) const;
51 | bool operator!=(const Rectangle& other) const;
52 |
53 | bool operator<(const Rectangle& other) const;
54 | bool operator>(const Rectangle& other) const;
55 |
56 | friend std::ostream& operator<<(std::ostream& stream, const Rectangle& Rectangle);
57 | };
58 |
59 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/mat4.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/String.h"
5 |
6 | #include "vec3.h"
7 | #include "vec4.h"
8 | #include "maths_func.h"
9 |
10 | namespace fl { namespace maths {
11 |
12 | struct Quaternion;
13 |
14 | struct FL_API mat4
15 | {
16 | union
17 | {
18 | // [row + col * 4]
19 | float elements[4 * 4];
20 | vec4 rows[4];
21 | };
22 |
23 | mat4();
24 | mat4(float diagonal);
25 | mat4(float* elements);
26 | mat4(const vec4& row0, const vec4& row1, const vec4& row2, const vec4& row3);
27 |
28 | static mat4 Identity();
29 |
30 | mat4& Multiply(const mat4& other);
31 | friend FL_API mat4 operator*(mat4 left, const mat4& right);
32 | mat4& operator*=(const mat4& other);
33 |
34 | vec3 Multiply(const vec3& other) const;
35 | friend FL_API vec3 operator*(const mat4& left, const vec3& right);
36 |
37 | vec4 Multiply(const vec4& other) const;
38 | friend FL_API vec4 operator*(const mat4& left, const vec4& right);
39 |
40 | mat4& Invert();
41 |
42 | vec4 GetColumn(int index) const;
43 | void SetColumn(uint index, const vec4& column);
44 | inline vec3 GetPosition() const { return vec3(GetColumn(3)); }
45 | inline void SetPosition(const vec3& position) { SetColumn(3, vec4(position, 1.0f)); }
46 |
47 | static mat4 Orthographic(float left, float right, float bottom, float top, float near, float far);
48 | static mat4 Perspective(float fov, float aspectRatio, float near, float far);
49 | static mat4 LookAt(const vec3& camera, const vec3& object, const vec3& up);
50 |
51 | static mat4 Translate(const vec3& translation);
52 | static mat4 Rotate(float angle, const vec3& axis);
53 | static mat4 Rotate(const Quaternion& quat);
54 | static mat4 Scale(const vec3& scale);
55 | static mat4 Invert(const mat4& matrix);
56 |
57 | static mat4 Transpose(const mat4& matrix);
58 |
59 | String ToString() const;
60 | };
61 |
62 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/maths.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include "maths_func.h"
5 |
6 | #include "vec2.h"
7 | #include "vec3.h"
8 | #include "vec4.h"
9 |
10 | #include "AABB.h"
11 | #include "Rectangle.h"
12 |
13 | #include "tvec2.h"
14 |
15 | #include "mat4.h"
16 |
17 | #include "Quaternion.h"
18 |
19 | namespace fl { namespace maths {
20 |
21 | typedef tvec2 ivec2;
22 | typedef tvec2 uvec2;
23 |
24 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/maths_func.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 |
5 | #include
6 |
7 | #define FL_PI 3.14159265358f
8 |
9 | namespace fl { namespace maths {
10 |
11 | FL_API inline float toRadians(float degrees)
12 | {
13 | return (float)(degrees * (FL_PI / 180.0f));
14 | }
15 |
16 | FL_API inline float toDegrees(float radians)
17 | {
18 | return (float)(radians * (180.0f / FL_PI));
19 | }
20 |
21 | FL_API inline int sign(float value)
22 | {
23 | return (value > 0) - (value < 0);
24 | }
25 |
26 | FL_API inline float sin(float angle)
27 | {
28 | return ::sin(angle);
29 | }
30 |
31 | FL_API inline float cos(float angle)
32 | {
33 | return ::cos(angle);
34 | }
35 |
36 | FL_API inline float tan(float angle)
37 | {
38 | return ::tan(angle);
39 | }
40 |
41 | FL_API inline float sqrt(float value)
42 | {
43 | return ::sqrt(value);
44 | }
45 |
46 | FL_API inline float rsqrt(float value)
47 | {
48 | return 1.0f / ::sqrt(value);
49 | }
50 |
51 | FL_API inline float asin(float value)
52 | {
53 | return ::asin(value);
54 | }
55 |
56 | FL_API inline float acos(float value)
57 | {
58 | return ::acos(value);
59 | }
60 |
61 | FL_API inline float atan(float value)
62 | {
63 | return ::atan(value);
64 | }
65 |
66 | FL_API inline float atan2(float y, float x)
67 | {
68 | return ::atan2(y, x);
69 | }
70 |
71 | FL_API inline float _min(float value, float minimum)
72 | {
73 | return (value < minimum) ? minimum : value;
74 | }
75 |
76 | FL_API inline float _max(float value, float maximum)
77 | {
78 | return (value > maximum) ? maximum : value;
79 | }
80 |
81 | FL_API inline float clamp(float value, float minimum, float maximum)
82 | {
83 | return (value > minimum) ? (value < maximum) ? value : maximum : minimum;
84 | }
85 |
86 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/tvec2.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include "fl/Common.h"
5 |
6 | namespace fl { namespace maths {
7 |
8 | template
9 | struct tvec2
10 | {
11 | T x, y;
12 |
13 | tvec2();
14 | tvec2(const T& x, const T& y);
15 |
16 | tvec2& Add(const tvec2& other);
17 | tvec2& Subtract(const tvec2& other);
18 | tvec2& Multiply(const tvec2& other);
19 | tvec2& Divide(const tvec2& other);
20 |
21 | friend tvec2 operator+(tvec2 left, const tvec2& right);
22 | friend tvec2 operator-(tvec2 left, const tvec2& right);
23 | friend tvec2 operator*(tvec2 left, const tvec2& right);
24 | friend tvec2 operator/(tvec2 left, const tvec2& right);
25 |
26 | bool operator==(const tvec2& other);
27 | bool operator!=(const tvec2& other);
28 |
29 | tvec2& operator+=(const tvec2& other);
30 | tvec2& operator-=(const tvec2& other);
31 | tvec2& operator*=(const tvec2& other);
32 | tvec2& operator/=(const tvec2& other);
33 |
34 | friend std::ostream& operator<<(std::ostream& stream, const tvec2& vector);
35 | };
36 |
37 | template
38 | tvec2::tvec2()
39 | {
40 | x = 0;
41 | y = 0;
42 | }
43 |
44 | template
45 | tvec2::tvec2(const T& x, const T& y)
46 | {
47 | this->x = x;
48 | this->y = y;
49 | }
50 |
51 | template
52 | tvec2& tvec2::Add(const tvec2& other)
53 | {
54 | x += other.x;
55 | y += other.y;
56 |
57 | return *this;
58 | }
59 |
60 | template
61 | tvec2& tvec2::Subtract(const tvec2& other)
62 | {
63 | x -= other.x;
64 | y -= other.y;
65 |
66 | return *this;
67 | }
68 |
69 | template
70 | tvec2& tvec2::Multiply(const tvec2& other)
71 | {
72 | x *= other.x;
73 | y *= other.y;
74 |
75 | return *this;
76 | }
77 |
78 | template
79 | tvec2& tvec2::Divide(const tvec2& other)
80 | {
81 | x /= other.x;
82 | y /= other.y;
83 |
84 | return *this;
85 | }
86 |
87 | template
88 | tvec2 operator+(tvec2 left, const tvec2& right)
89 | {
90 | return left.Add(right);
91 | }
92 |
93 | template
94 | tvec2 operator-(tvec2 left, const tvec2& right)
95 | {
96 | return left.Subtract(right);
97 | }
98 |
99 | template
100 | tvec2 operator*(tvec2 left, const tvec2& right)
101 | {
102 | return left.Multiply(right);
103 | }
104 |
105 | template
106 | tvec2 operator/(tvec2 left, const tvec2& right)
107 | {
108 | return left.Divide(right);
109 | }
110 |
111 | template
112 | tvec2& tvec2::operator+=(const tvec2& other)
113 | {
114 | return Add(other);
115 | }
116 |
117 | template
118 | tvec2& tvec2::operator-=(const tvec2& other)
119 | {
120 | return Subtract(other);
121 | }
122 |
123 | template
124 | tvec2& tvec2::operator*=(const tvec2& other)
125 | {
126 | return Multiply(other);
127 | }
128 |
129 | template
130 | tvec2& tvec2::operator/=(const tvec2& other)
131 | {
132 | return Divide(other);
133 | }
134 |
135 | template
136 | bool tvec2::operator==(const tvec2& other)
137 | {
138 | return x == other.x && y == other.y;
139 | }
140 |
141 | template
142 | bool tvec2::operator!=(const tvec2& other)
143 | {
144 | return !(*this == other);
145 | }
146 |
147 | template
148 | std::ostream& operator<<(std::ostream& stream, const tvec2& vector)
149 | {
150 | stream << "tvec2: (" << vector.x << ", " << vector.y << ")";
151 | return stream;
152 | }
153 |
154 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/vec2.cpp:
--------------------------------------------------------------------------------
1 | #include "vec2.h"
2 |
3 | #include
4 |
5 | namespace fl { namespace maths {
6 |
7 | vec2::vec2(float scalar)
8 | : x(scalar), y(scalar)
9 | {
10 | }
11 |
12 | vec2::vec2(float x, float y)
13 | : x(x), y(y)
14 | {
15 | }
16 |
17 | vec2::vec2(const vec3& vector)
18 | {
19 | this->x = vector.x;
20 | this->y = vector.y;
21 | }
22 |
23 | vec2& vec2::Add(const vec2& other)
24 | {
25 | x += other.x;
26 | y += other.y;
27 |
28 | return *this;
29 | }
30 |
31 | vec2& vec2::Subtract(const vec2& other)
32 | {
33 | x -= other.x;
34 | y -= other.y;
35 |
36 | return *this;
37 | }
38 |
39 | vec2& vec2::Multiply(const vec2& other)
40 | {
41 | x *= other.x;
42 | y *= other.y;
43 |
44 | return *this;
45 | }
46 |
47 | vec2& vec2::Divide(const vec2& other)
48 | {
49 | x /= other.x;
50 | y /= other.y;
51 |
52 | return *this;
53 | }
54 |
55 | vec2& vec2::Add(float value)
56 | {
57 | x += value;
58 | y += value;
59 |
60 | return *this;
61 | }
62 |
63 | vec2& vec2::Subtract(float value)
64 | {
65 | x -= value;
66 | y -= value;
67 |
68 | return *this;
69 | }
70 |
71 | vec2& vec2::Multiply(float value)
72 | {
73 | x *= value;
74 | y *= value;
75 |
76 | return *this;
77 | }
78 |
79 | vec2& vec2::Divide(float value)
80 | {
81 | x /= value;
82 | y /= value;
83 |
84 | return *this;
85 | }
86 |
87 | vec2 operator+(vec2 left, const vec2& right)
88 | {
89 | return left.Add(right);
90 | }
91 |
92 | vec2 operator-(vec2 left, const vec2& right)
93 | {
94 | return left.Subtract(right);
95 | }
96 |
97 | vec2 operator*(vec2 left, const vec2& right)
98 | {
99 | return left.Multiply(right);
100 | }
101 |
102 | vec2 operator/(vec2 left, const vec2& right)
103 | {
104 | return left.Divide(right);
105 | }
106 |
107 | vec2 operator+(vec2 left, float value)
108 | {
109 | return vec2(left.x + value, left.y + value);
110 | }
111 |
112 | vec2 operator-(vec2 left, float value)
113 | {
114 | return vec2(left.x - value, left.y - value);
115 | }
116 |
117 | vec2 operator*(vec2 left, float value)
118 | {
119 | return vec2(left.x * value, left.y * value);
120 | }
121 |
122 | vec2 operator/(vec2 left, float value)
123 | {
124 | return vec2(left.x / value, left.y / value);
125 | }
126 |
127 | vec2& vec2::operator+=(const vec2& other)
128 | {
129 | return Add(other);
130 | }
131 |
132 | vec2& vec2::operator-=(const vec2& other)
133 | {
134 | return Subtract(other);
135 | }
136 |
137 | vec2& vec2::operator*=(const vec2& other)
138 | {
139 | return Multiply(other);
140 | }
141 |
142 | vec2& vec2::operator/=(const vec2& other)
143 | {
144 | return Divide(other);
145 | }
146 |
147 | vec2& vec2::operator+=(float value)
148 | {
149 | return Add(value);
150 | }
151 |
152 | vec2& vec2::operator-=(float value)
153 | {
154 | return Subtract(value);
155 | }
156 |
157 | vec2& vec2::operator*=(float value)
158 | {
159 | return Multiply(value);
160 | }
161 |
162 | vec2& vec2::operator/=(float value)
163 | {
164 | return Divide(value);
165 | }
166 |
167 | bool vec2::operator==(const vec2& other) const
168 | {
169 | return x == other.x && y == other.y;
170 | }
171 |
172 | bool vec2::operator!=(const vec2& other) const
173 | {
174 | return !(*this == other);
175 | }
176 |
177 | bool vec2::operator<(const vec2& other) const
178 | {
179 | return x < other.x && y < other.y;
180 | }
181 |
182 | bool vec2::operator<=(const vec2& other) const
183 | {
184 | return x <= other.x && y <= other.y;
185 | }
186 |
187 | bool vec2::operator>(const vec2& other) const
188 | {
189 | return x > other.x && y > other.y;
190 | }
191 |
192 | bool vec2::operator>=(const vec2& other) const
193 | {
194 | return x >= other.x && y >= other.y;
195 | }
196 |
197 | float vec2::Distance(const vec2& other) const
198 | {
199 | float a = x - other.x;
200 | float b = y - other.y;
201 | return sqrt(a * a + b * b);
202 | }
203 |
204 | float vec2::Dot(const vec2& other) const
205 | {
206 | return x * other.x + y * other.y;
207 | }
208 |
209 | float vec2::Magnitude() const
210 | {
211 | return sqrt(x * x + y * y);
212 | }
213 |
214 | vec2 vec2::Normalise() const
215 | {
216 | float length = Magnitude();
217 | return vec2(x / length, y / length);
218 | }
219 |
220 | String vec2::ToString() const
221 | {
222 | std::stringstream result;
223 | result << "vec2: (" << x << ", " << y << ")";
224 | return result.str();
225 | }
226 |
227 | std::ostream& operator<<(std::ostream& stream, const vec2& vector)
228 | {
229 | stream << vector.ToString();
230 | return stream;
231 | }
232 |
233 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/vec2.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/String.h"
5 |
6 | #include "vec3.h"
7 |
8 | namespace fl { namespace maths {
9 |
10 | struct FL_API vec2
11 | {
12 | float x, y;
13 |
14 | vec2() = default;
15 | vec2(float scalar);
16 | vec2(float x, float y);
17 | vec2(const vec3& vector);
18 |
19 | vec2& Add(const vec2& other);
20 | vec2& Subtract(const vec2& other);
21 | vec2& Multiply(const vec2& other);
22 | vec2& Divide(const vec2& other);
23 |
24 | vec2& Add(float value);
25 | vec2& Subtract(float value);
26 | vec2& Multiply(float value);
27 | vec2& Divide(float value);
28 |
29 | friend vec2 operator+(vec2 left, const vec2& right);
30 | friend vec2 operator-(vec2 left, const vec2& right);
31 | friend vec2 operator*(vec2 left, const vec2& right);
32 | friend vec2 operator/(vec2 left, const vec2& right);
33 |
34 | friend vec2 operator+(vec2 left, float value);
35 | friend vec2 operator-(vec2 left, float value);
36 | friend vec2 operator*(vec2 left, float value);
37 | friend vec2 operator/(vec2 left, float value);
38 |
39 | bool operator==(const vec2& other) const;
40 | bool operator!=(const vec2& other) const;
41 |
42 | vec2& operator+=(const vec2& other);
43 | vec2& operator-=(const vec2& other);
44 | vec2& operator*=(const vec2& other);
45 | vec2& operator/=(const vec2& other);
46 |
47 | vec2& operator+=(float value);
48 | vec2& operator-=(float value);
49 | vec2& operator*=(float value);
50 | vec2& operator/=(float value);
51 |
52 | bool operator<(const vec2& other) const;
53 | bool operator<=(const vec2& other) const;
54 | bool operator>(const vec2& other) const;
55 | bool operator>=(const vec2& other) const;
56 |
57 | float Magnitude() const;
58 | vec2 Normalise() const;
59 | float Distance(const vec2& other) const;
60 | float Dot(const vec2& other) const;
61 |
62 | String ToString() const;
63 |
64 | friend std::ostream& operator<<(std::ostream& stream, const vec2& vector);
65 | };
66 |
67 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/vec3.cpp:
--------------------------------------------------------------------------------
1 | #include "vec3.h"
2 |
3 | #include "vec2.h"
4 | #include "vec4.h"
5 | #include "mat4.h"
6 |
7 | namespace fl { namespace maths {
8 |
9 | vec3::vec3()
10 | : x(0.0f), y(0.0f), z(0.0f)
11 | {
12 | }
13 |
14 | vec3::vec3(float scalar)
15 | : x(scalar), y(scalar), z(scalar)
16 | {
17 | }
18 |
19 | vec3::vec3(float x, float y, float z)
20 | : x(x), y(y), z(z)
21 | {
22 | }
23 |
24 | vec3::vec3(const vec2& other)
25 | : x(other.x), y(other.y), z(0.0f)
26 | {
27 | }
28 |
29 | vec3::vec3(float x, float y)
30 | : x(x), y(y), z(0.0f)
31 | {
32 | }
33 |
34 | vec3::vec3(const vec4& other)
35 | : x(other.x), y(other.y), z(other.z)
36 | {
37 | }
38 |
39 | vec3 vec3::Up()
40 | {
41 | return vec3(0.0f, 1.0f, 0.0f);
42 | }
43 |
44 | vec3 vec3::Down()
45 | {
46 | return vec3(0.0f, -1.0f, 0.0f);
47 | }
48 |
49 | vec3 vec3::Left()
50 | {
51 | return vec3(-1.0f, 0.0f, 0.0f);
52 | }
53 |
54 | vec3 vec3::Right()
55 | {
56 | return vec3(1.0f, 1.0f, 0.0f);
57 | }
58 |
59 | vec3 vec3::Zero()
60 | {
61 | return vec3(0.0f, 0.0f, 0.0f);
62 | }
63 |
64 | vec3 vec3::XAxis()
65 | {
66 | return vec3(1.0f, 0.0f, 0.0f);
67 | }
68 |
69 | vec3 vec3::YAxis()
70 | {
71 | return vec3(0.0f, 1.0f, 0.0f);
72 | }
73 |
74 | vec3 vec3::ZAxis()
75 | {
76 | return vec3(0.0f, 0.0f, 1.0f);
77 | }
78 |
79 | vec3& vec3::Add(const vec3& other)
80 | {
81 | x += other.x;
82 | y += other.y;
83 | z += other.z;
84 |
85 | return *this;
86 | }
87 |
88 | vec3& vec3::Subtract(const vec3& other)
89 | {
90 | x -= other.x;
91 | y -= other.y;
92 | z -= other.z;
93 |
94 | return *this;
95 | }
96 |
97 | vec3& vec3::Multiply(const vec3& other)
98 | {
99 | x *= other.x;
100 | y *= other.y;
101 | z *= other.z;
102 |
103 | return *this;
104 | }
105 |
106 | vec3& vec3::Divide(const vec3& other)
107 | {
108 | x /= other.x;
109 | y /= other.y;
110 | z /= other.z;
111 |
112 | return *this;
113 | }
114 |
115 | vec3& vec3::Add(float other)
116 | {
117 | x += other;
118 | y += other;
119 | z += other;
120 |
121 | return *this;
122 | }
123 |
124 | vec3& vec3::Subtract(float other)
125 | {
126 | x -= other;
127 | y -= other;
128 | z -= other;
129 |
130 | return *this;
131 | }
132 |
133 | vec3& vec3::Multiply(float other)
134 | {
135 | x *= other;
136 | y *= other;
137 | z *= other;
138 |
139 | return *this;
140 | }
141 |
142 | vec3& vec3::Divide(float other)
143 | {
144 | x /= other;
145 | y /= other;
146 | z /= other;
147 |
148 | return *this;
149 | }
150 |
151 | vec3 vec3::Multiply(const mat4& transform) const
152 | {
153 | return vec3(
154 | transform.rows[0].x * x + transform.rows[0].y * y + transform.rows[0].z * z + transform.rows[0].w,
155 | transform.rows[1].x * x + transform.rows[1].y * y + transform.rows[1].z * z + transform.rows[1].w,
156 | transform.rows[2].x * x + transform.rows[2].y * y + transform.rows[2].z * z + transform.rows[2].w
157 | );
158 | }
159 |
160 | vec3 operator+(vec3 left, const vec3& right)
161 | {
162 | return left.Add(right);
163 | }
164 |
165 | vec3 operator-(vec3 left, const vec3& right)
166 | {
167 | return left.Subtract(right);
168 | }
169 |
170 | vec3 operator*(vec3 left, const vec3& right)
171 | {
172 | return left.Multiply(right);
173 | }
174 |
175 | vec3 operator/(vec3 left, const vec3& right)
176 | {
177 | return left.Divide(right);
178 | }
179 |
180 | vec3 operator+(vec3 left, float right)
181 | {
182 | return left.Add(right);
183 | }
184 |
185 | vec3 operator-(vec3 left, float right)
186 | {
187 | return left.Subtract(right);
188 | }
189 |
190 | vec3 operator*(vec3 left, float right)
191 | {
192 | return left.Multiply(right);
193 | }
194 |
195 | vec3 operator/(vec3 left, float right)
196 | {
197 | return left.Divide(right);
198 | }
199 |
200 | vec3& vec3::operator+=(const vec3& other)
201 | {
202 | return Add(other);
203 | }
204 |
205 | vec3& vec3::operator-=(const vec3& other)
206 | {
207 | return Subtract(other);
208 | }
209 |
210 | vec3& vec3::operator*=(const vec3& other)
211 | {
212 | return Multiply(other);
213 | }
214 |
215 | vec3& vec3::operator/=(const vec3& other)
216 | {
217 | return Divide(other);
218 | }
219 |
220 | vec3& vec3::operator+=(float other)
221 | {
222 | return Add(other);
223 | }
224 |
225 | vec3& vec3::operator-=(float other)
226 | {
227 | return Subtract(other);
228 | }
229 |
230 | vec3& vec3::operator*=(float other)
231 | {
232 | return Multiply(other);
233 | }
234 |
235 | vec3& vec3::operator/=(float other)
236 | {
237 | return Divide(other);
238 | }
239 |
240 | bool vec3::operator<(const vec3& other) const
241 | {
242 | return x < other.x && y < other.y && z < other.z;
243 | }
244 |
245 | bool vec3::operator<=(const vec3& other) const
246 | {
247 | return x <= other.x && y <= other.y && z <= other.z;
248 | }
249 |
250 | bool vec3::operator>(const vec3& other) const
251 | {
252 | return x > other.x && y > other.y && z > other.z;
253 | }
254 |
255 | bool vec3::operator>=(const vec3& other) const
256 | {
257 | return x >= other.x && y >= other.y && z >= other.z;
258 | }
259 |
260 | bool vec3::operator==(const vec3& other) const
261 | {
262 | return x == other.x && y == other.y && z == other.z;
263 | }
264 |
265 | bool vec3::operator!=(const vec3& other) const
266 | {
267 | return !(*this == other);
268 | }
269 |
270 | vec3 operator-(const vec3& vector)
271 | {
272 | return vec3(-vector.x, -vector.y, -vector.z);
273 | }
274 |
275 | vec3 vec3::Cross(const vec3& other) const
276 | {
277 | return vec3(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
278 | }
279 |
280 | float vec3::Dot(const vec3& other) const
281 | {
282 | return x * other.x + y * other.y + z * other.z;
283 | }
284 |
285 | float vec3::Magnitude() const
286 | {
287 | return sqrt(x * x + y * y + z * z);
288 | }
289 |
290 | vec3 vec3::Normalize() const
291 | {
292 | float length = Magnitude();
293 | return vec3(x / length, y / length, z / length);
294 | }
295 |
296 | float vec3::Distance(const vec3& other) const
297 | {
298 | float a = x - other.x;
299 | float b = y - other.y;
300 | float c = z - other.z;
301 | return sqrt(a * a + b * b + c * c);
302 | }
303 |
304 | std::ostream& operator<<(std::ostream& stream, const vec3& vector)
305 | {
306 | stream << "vec3: (" << vector.x << ", " << vector.y << ", " << vector.z << ")";
307 | return stream;
308 | }
309 |
310 |
311 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/vec3.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 |
5 | namespace fl { namespace maths {
6 |
7 | struct vec2;
8 | struct vec4;
9 | struct mat4;
10 |
11 | struct FL_API vec3
12 | {
13 | float x, y, z;
14 |
15 | vec3();
16 | vec3(float scalar);
17 | vec3(float x, float y, float z);
18 | vec3(const vec2& other);
19 | vec3(float x, float y);
20 | vec3(const vec4& other);
21 |
22 | static vec3 Up();
23 | static vec3 Down();
24 | static vec3 Left();
25 | static vec3 Right();
26 | static vec3 Zero();
27 |
28 | static vec3 XAxis();
29 | static vec3 YAxis();
30 | static vec3 ZAxis();
31 |
32 | vec3& Add(const vec3& other);
33 | vec3& Subtract(const vec3& other);
34 | vec3& Multiply(const vec3& other);
35 | vec3& Divide(const vec3& other);
36 |
37 | vec3& Add(float other);
38 | vec3& Subtract(float other);
39 | vec3& Multiply(float other);
40 | vec3& Divide(float other);
41 |
42 | vec3 Multiply(const mat4& transform) const;
43 |
44 | friend vec3 operator+(vec3 left, const vec3& right);
45 | friend vec3 operator-(vec3 left, const vec3& right);
46 | friend vec3 operator*(vec3 left, const vec3& right);
47 | friend vec3 operator/(vec3 left, const vec3& right);
48 |
49 | friend vec3 operator+(vec3 left, float right);
50 | friend vec3 operator-(vec3 left, float right);
51 | friend vec3 operator*(vec3 left, float right);
52 | friend vec3 operator/(vec3 left, float right);
53 |
54 | bool operator==(const vec3& other) const;
55 | bool operator!=(const vec3& other) const;
56 |
57 | vec3& operator+=(const vec3& other);
58 | vec3& operator-=(const vec3& other);
59 | vec3& operator*=(const vec3& other);
60 | vec3& operator/=(const vec3& other);
61 |
62 | vec3& operator+=(float other);
63 | vec3& operator-=(float other);
64 | vec3& operator*=(float other);
65 | vec3& operator/=(float other);
66 |
67 | bool operator<(const vec3& other) const;
68 | bool operator<=(const vec3& other) const;
69 | bool operator>(const vec3& other) const;
70 | bool operator>=(const vec3& other) const;
71 |
72 | friend vec3 operator-(const vec3& vector);
73 |
74 | vec3 Cross(const vec3& other) const;
75 | float Dot(const vec3& other) const;
76 |
77 | float Magnitude() const;
78 | vec3 Normalize() const;
79 | float Distance(const vec3& other) const;
80 |
81 | friend std::ostream& operator<<(std::ostream& stream, const vec3& vector);
82 | };
83 |
84 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/vec4.cpp:
--------------------------------------------------------------------------------
1 | #include "vec4.h"
2 |
3 | #include "mat4.h"
4 |
5 | namespace fl { namespace maths {
6 |
7 | vec4::vec4(float scalar)
8 | : x(scalar), y(scalar), z(scalar), w(scalar)
9 | {
10 | }
11 |
12 | vec4::vec4(float x, float y, float z, float w)
13 | : x(x), y(y), z(z), w(w)
14 | {
15 | }
16 |
17 | vec4::vec4(const vec3& xyz, float w)
18 | : x(xyz.x), y(xyz.y), z(xyz.z), w(w)
19 | {
20 | }
21 |
22 | vec4& vec4::Add(const vec4& other)
23 | {
24 | x += other.x;
25 | y += other.y;
26 | z += other.z;
27 | w += other.w;
28 |
29 | return *this;
30 | }
31 |
32 | vec4& vec4::Subtract(const vec4& other)
33 | {
34 | x -= other.x;
35 | y -= other.y;
36 | z -= other.z;
37 | w -= other.w;
38 |
39 | return *this;
40 | }
41 |
42 | vec4& vec4::Multiply(const vec4& other)
43 | {
44 | x *= other.x;
45 | y *= other.y;
46 | z *= other.z;
47 | w *= other.w;
48 |
49 | return *this;
50 | }
51 |
52 | vec4& vec4::Divide(const vec4& other)
53 | {
54 | x /= other.x;
55 | y /= other.y;
56 | z /= other.z;
57 | w /= other.w;
58 |
59 | return *this;
60 | }
61 |
62 | vec4 vec4::Multiply(const mat4& transform) const
63 | {
64 | return vec4(
65 | transform.rows[0].x * x + transform.rows[0].y * y + transform.rows[0].z * z + transform.rows[0].w * w,
66 | transform.rows[1].x * x + transform.rows[1].y * y + transform.rows[1].z * z + transform.rows[1].w * w,
67 | transform.rows[2].x * x + transform.rows[2].y * y + transform.rows[2].z * z + transform.rows[2].w * w,
68 | transform.rows[3].x * x + transform.rows[3].y * y + transform.rows[3].z * z + transform.rows[3].w * w
69 | );
70 | }
71 |
72 | vec4 operator+(vec4 left, const vec4& right)
73 | {
74 | return left.Add(right);
75 | }
76 |
77 | vec4 operator-(vec4 left, const vec4& right)
78 | {
79 | return left.Subtract(right);
80 | }
81 |
82 | vec4 operator*(vec4 left, const vec4& right)
83 | {
84 | return left.Multiply(right);
85 | }
86 |
87 | vec4 operator/(vec4 left, const vec4& right)
88 | {
89 | return left.Divide(right);
90 | }
91 |
92 | vec4& vec4::operator+=(const vec4& other)
93 | {
94 | return Add(other);
95 | }
96 |
97 | vec4& vec4::operator-=(const vec4& other)
98 | {
99 | return Subtract(other);
100 | }
101 |
102 | vec4& vec4::operator*=(const vec4& other)
103 | {
104 | return Multiply(other);
105 | }
106 |
107 | vec4& vec4::operator/=(const vec4& other)
108 | {
109 | return Divide(other);
110 | }
111 |
112 | bool vec4::operator==(const vec4& other)
113 | {
114 | return x == other.x && y == other.y && z == other.z && w == other.w;
115 | }
116 |
117 | bool vec4::operator!=(const vec4& other)
118 | {
119 | return !(*this == other);
120 | }
121 |
122 | float vec4::Dot(const vec4& other)
123 | {
124 | return x * other.x + y * other.y + z * other.z + w * other.w;
125 | }
126 |
127 | std::ostream& operator<<(std::ostream& stream, const vec4& vector)
128 | {
129 | stream << "vec4: (" << vector.x << ", " << vector.y << ", " << vector.z << ", " << vector.w << ")";
130 | return stream;
131 | }
132 |
133 |
134 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/maths/vec4.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 |
5 | #include "vec3.h"
6 |
7 | namespace fl { namespace maths {
8 |
9 | struct mat4;
10 |
11 | struct FL_API vec4
12 | {
13 | float x, y, z, w;
14 |
15 | vec4() = default;
16 | vec4(float scalar);
17 | vec4(float x, float y, float z, float w);
18 | vec4(const vec3& xyz, float w);
19 |
20 | vec4& Add(const vec4& other);
21 | vec4& Subtract(const vec4& other);
22 | vec4& Multiply(const vec4& other);
23 | vec4& Divide(const vec4& other);
24 |
25 | vec4 Multiply(const mat4& transform) const;
26 |
27 | friend vec4 operator+(vec4 left, const vec4& right);
28 | friend vec4 operator-(vec4 left, const vec4& right);
29 | friend vec4 operator*(vec4 left, const vec4& right);
30 | friend vec4 operator/(vec4 left, const vec4& right);
31 |
32 | bool operator==(const vec4& other);
33 | bool operator!=(const vec4& other);
34 |
35 | vec4& operator+=(const vec4& other);
36 | vec4& operator-=(const vec4& other);
37 | vec4& operator*=(const vec4& other);
38 | vec4& operator/=(const vec4& other);
39 |
40 | float Dot(const vec4& other);
41 |
42 | friend std::ostream& operator<<(std::ostream& stream, const vec4& vector);
43 | };
44 |
45 | } }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/platform/android/AndroidFileSystem.cpp:
--------------------------------------------------------------------------------
1 | #include "fl/system/FileSystem.h"
2 |
3 | #include
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | namespace fl {
10 |
11 | extern JNIEnv* g_Env;
12 | extern jobject g_MainView;
13 | extern AAssetManager* g_AssetManager;
14 |
15 | bool FileSystem::FileExists(const String& path)
16 | {
17 | return false;
18 | }
19 |
20 | int FileSystem::GetFileSize(const String& path)
21 | {
22 | return 0;
23 | }
24 |
25 | byte* FileSystem::ReadFile(const String& path, size_t* outSize)
26 | {
27 | FL_ASSERT(g_AssetManager);
28 |
29 | FL_LOG("Reading file '%s'...", path.c_str());
30 | AAsset* file = AAssetManager_open(g_AssetManager, path.c_str(), AASSET_MODE_BUFFER);
31 | FL_ASSERT(file);
32 | if (!file)
33 | return nullptr;
34 |
35 | size_t size = AAsset_getLength(file);
36 | if (outSize)
37 | *outSize = size;
38 |
39 | byte* result = new byte[size];
40 | AAsset_read(file, result, size);
41 | AAsset_close(file);
42 | return result;
43 | }
44 |
45 | bool FileSystem::ReadFile(const String& path, void* buffer, long long size)
46 | {
47 | return false;
48 | }
49 |
50 | String FileSystem::ReadTextFile(const String& path)
51 | {
52 | FL_ASSERT(g_AssetManager);
53 |
54 | FL_LOG("Reading file '%s'...", path.c_str());
55 | AAsset* file = AAssetManager_open(g_AssetManager, path.c_str(), AASSET_MODE_BUFFER);
56 |
57 | if (!file)
58 | return "";
59 |
60 | size_t size = AAsset_getLength(file);
61 | FL_ASSERT(size < 100 * 1024 * 1024);
62 |
63 | String result(size, 0);
64 | AAsset_read(file, &result[0], size);
65 | AAsset_close(file);
66 |
67 | // Strip carriage returns
68 | result.erase(std::remove(result.begin(), result.end(), '\r'), result.end());
69 | return result;
70 | }
71 |
72 | bool FileSystem::WriteFile(const String& path, byte* buffer)
73 | {
74 | return false;
75 | }
76 |
77 | bool FileSystem::WriteTextFile(const String& path, const String& text)
78 | {
79 | return false;
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/platform/android/AndroidRenderer.cpp:
--------------------------------------------------------------------------------
1 | #include "fl/graphics/Renderer.h"
2 |
3 | #include "fl/gl.h"
4 |
5 | namespace fl {
6 |
7 | void Renderer::Init()
8 | {
9 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
10 | glEnable(GL_BLEND);
11 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
12 | }
13 |
14 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/platform/android/AndroidSystem.cpp:
--------------------------------------------------------------------------------
1 | #include "AndroidSystem.h"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | namespace fl {
8 |
9 | JNIEnv* g_Env;
10 | jobject g_MainView;
11 | AAssetManager* g_AssetManager = nullptr;
12 |
13 | void AndroidSystem::Init(JNIEnv* env, jobject mainView)
14 | {
15 | g_Env = env;
16 | g_MainView = mainView;
17 |
18 | // Init AssetManager
19 | jmethodID getAssets = env->GetMethodID(env->GetObjectClass(mainView), "getAssets", "()Landroid/content/res/AssetManager;");
20 | g_AssetManager = AAssetManager_fromJava(env, env->CallObjectMethod(mainView, getAssets));
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/platform/android/AndroidSystem.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace fl {
6 |
7 | class AndroidSystem
8 | {
9 | public:
10 | static void Init(JNIEnv* env, jobject mainView);
11 | };
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/platform/windows/WindowsFileSystem.cpp:
--------------------------------------------------------------------------------
1 | #include "fl/system/FileSystem.h"
2 |
3 | #include
4 |
5 | namespace fl {
6 |
7 | bool FileSystem::FileExists(const String& path)
8 | {
9 | return false;
10 | }
11 |
12 | int FileSystem::GetFileSize(const String& path)
13 | {
14 | return 0;
15 | }
16 |
17 | byte* FileSystem::ReadFile(const String& path, size_t* outSize)
18 | {
19 | FILE* file = fopen(path.c_str(), "rb");
20 | FL_ASSERT(file);
21 | // FL_ASSERT(file, "Could not open file '", filepath, "'!");
22 |
23 | fseek(file, 0, SEEK_END);
24 | size_t length = ftell(file);
25 | fseek(file, 0, SEEK_SET);
26 | FL_ASSERT(length < 100 * 1024 * 1024);
27 | if (outSize)
28 | *outSize = length;
29 | byte* result = new byte[length];
30 | #ifdef FL_DEBUG
31 | memset(result, 0xCA, length);
32 | #endif
33 | fread(result, 1, length, file);
34 | fclose(file);
35 | return result;
36 | }
37 |
38 | bool FileSystem::ReadFile(const String& path, void* buffer, long long size)
39 | {
40 | return false;
41 | }
42 |
43 | String FileSystem::ReadTextFile(const String& path)
44 | {
45 | FILE* file = fopen(path.c_str(), "rb");
46 | FL_ASSERT(file);
47 |
48 | fseek(file, 0, SEEK_END);
49 | int length = ftell(file);
50 | FL_ASSERT(length < 100 * 1024 * 1024);
51 | String result(length, 0);
52 | fseek(file, 0, SEEK_SET);
53 | fread(&result[0], 1, length, file);
54 | fclose(file);
55 |
56 | // Strip carriage returns
57 | result.erase(std::remove(result.begin(), result.end(), '\r'), result.end());
58 | return result;
59 | }
60 |
61 | bool FileSystem::WriteFile(const String& path, byte* buffer)
62 | {
63 | return false;
64 | }
65 |
66 | bool FileSystem::WriteTextFile(const String& path, const String& text)
67 | {
68 | return false;
69 | }
70 |
71 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/platform/windows/WindowsRenderer.cpp:
--------------------------------------------------------------------------------
1 | #include "fl/graphics/Renderer.h"
2 |
3 | #include
4 | #include
5 |
6 | namespace fl {
7 |
8 | void Renderer::Init()
9 | {
10 | if (glewInit() != GLEW_OK)
11 | {
12 | std::cout << "Unable to initialize GLEW!" << std::endl;
13 | return;
14 | }
15 |
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/system/FileSystem.cpp:
--------------------------------------------------------------------------------
1 | #include "FileSystem.h"
2 |
3 | #include
4 |
5 | namespace fl {
6 |
7 | bool FileSystem::FileExists(const String& path)
8 | {
9 | return false;
10 | }
11 |
12 | int FileSystem::GetFileSize(const String& path)
13 | {
14 | return 0;
15 | }
16 |
17 | byte* FileSystem::ReadFile(const String& path, size_t* outSize)
18 | {
19 | FILE* file = fopen(path.c_str(), "rb");
20 | FL_ASSERT(file);
21 | // FL_ASSERT(file, "Could not open file '", filepath, "'!");
22 |
23 | fseek(file, 0, SEEK_END);
24 | size_t length = ftell(file);
25 | FL_ASSERT(length < 100 * 1024 * 1024);
26 | if (outSize)
27 | *outSize = length;
28 | byte* result = new byte[length];
29 | fread(result, 1, length, file);
30 | fclose(file);
31 | return result;
32 | }
33 |
34 | bool FileSystem::ReadFile(const String& path, void* buffer, long long size)
35 | {
36 | return false;
37 | }
38 |
39 | String FileSystem::ReadTextFile(const String& path)
40 | {
41 | FILE* file = fopen(path.c_str(), "rb");
42 | FL_ASSERT(file);
43 |
44 | fseek(file, 0, SEEK_END);
45 | int length = ftell(file);
46 | FL_ASSERT(length < 100 * 1024 * 1024);
47 | String result(length, 0);
48 | fseek(file, 0, SEEK_SET);
49 | fread(&result[0], 1, length, file);
50 | fclose(file);
51 |
52 | // Strip carriage returns
53 | result.erase(std::remove(result.begin(), result.end(), '\r'), result.end());
54 | return result;
55 | }
56 |
57 | bool FileSystem::WriteFile(const String& path, byte* buffer)
58 | {
59 | return false;
60 | }
61 |
62 | bool FileSystem::WriteTextFile(const String& path, const String& text)
63 | {
64 | return false;
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/system/FileSystem.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/String.h"
5 |
6 | namespace fl {
7 |
8 | class FL_API FileSystem
9 | {
10 | public:
11 | static bool FileExists(const String& path);
12 | static int GetFileSize(const String& path);
13 |
14 | static byte* ReadFile(const String& path, size_t* outSize = nullptr);
15 | static bool ReadFile(const String& path, void* buffer, long long size = -1);
16 | static String ReadTextFile(const String& path);
17 |
18 | static bool WriteFile(const String& path, byte* buffer);
19 | static bool WriteTextFile(const String& path, const String& text);
20 | };
21 |
22 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/system/Timer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | class Timer
6 | {
7 | private:
8 | typedef std::chrono::high_resolution_clock HighResolutionClock;
9 | typedef std::chrono::duration milliseconds_type;
10 |
11 | std::chrono::time_point m_Start;
12 | public:
13 | inline Timer()
14 | {
15 | Reset();
16 | }
17 |
18 | inline void Reset()
19 | {
20 | m_Start = HighResolutionClock::now();
21 | }
22 |
23 | inline float Elapsed()
24 | {
25 | return std::chrono::duration_cast(HighResolutionClock::now() - m_Start).count() / 1000.0f;
26 | }
27 |
28 | inline float ElapsedMillis()
29 | {
30 | return Elapsed() * 1000.0f;
31 | }
32 | };
33 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/xml/XMLDocument.cpp:
--------------------------------------------------------------------------------
1 | #include "XMLDocument.h"
2 | #include "fl/system/FileSystem.h"
3 |
4 | using namespace rapidxml;
5 |
6 | namespace fl {
7 |
8 | const XMLNode* XMLNode::NullNode = new XMLNode("NULL", *(XMLNode*)NULL);
9 |
10 | XMLDocument::XMLDocument(const String& filepath)
11 | : m_Filepath(filepath)
12 | {
13 | String file = FileSystem::ReadTextFile(filepath);
14 |
15 | xml_document<> doc;
16 | doc.parse<0>((char*)file.c_str());
17 |
18 | xml_node<>* root = doc.first_node();
19 | m_RootNode = new XMLNode(root->name());
20 |
21 | ParseNodeChildren(root, *m_RootNode);
22 | ParseAllAttributes(root, m_RootNode->attributes);
23 | }
24 |
25 | XMLDocument::~XMLDocument()
26 | {
27 | delete m_RootNode;
28 | }
29 |
30 | XMLNode* XMLDocument::FindNode(const String& name)
31 | {
32 | if (m_RootNode->name == name)
33 | return m_RootNode;
34 |
35 | return FindChild(*m_RootNode, name);
36 | }
37 |
38 | void XMLDocument::ParseAllAttributes(xml_node<>* node, std::vector& attributes)
39 | {
40 | for (xml_attribute<>* attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute())
41 | attributes.push_back({ String(attribute->name()), String(attribute->value()) });
42 | }
43 |
44 | void XMLDocument::ParseNodeChildren(rapidxml::xml_node<>* node, XMLNode& base)
45 | {
46 | for (xml_node<>* child = node->first_node(); child; child = child->next_sibling())
47 | {
48 | base.children.push_back(XMLNode(child->name(), child->value(), base));
49 | ParseAllAttributes(child, base.children.back().attributes);
50 | ParseNodeChildren(child, base.children.back());
51 | }
52 | }
53 |
54 | XMLNode* XMLDocument::FindChild(XMLNode& node, const String& name)
55 | {
56 | for (XMLNode& child : node.children)
57 | {
58 | if (child.name == name)
59 | return &child;
60 |
61 | return FindChild(child, name);
62 | }
63 | return nullptr;
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/xml/XMLDocument.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fl/Common.h"
4 | #include "fl/String.h"
5 | #include "rapidxml/rapidxml.hpp"
6 |
7 | namespace fl {
8 |
9 | struct FL_API XMLAttribute
10 | {
11 | String name;
12 | String value;
13 | };
14 |
15 | struct FL_API XMLNode
16 | {
17 | static const XMLNode* NullNode;
18 |
19 | String name;
20 | String value;
21 | std::vector attributes;
22 | std::vector children;
23 | const XMLNode& parent;
24 |
25 | XMLNode(const String& name, const XMLNode& parent = *NullNode)
26 | : name(name), parent(parent) {}
27 | XMLNode(const String& name, const String& value, const XMLNode& parent = *NullNode)
28 | : name(name), value(value), parent(parent) {}
29 |
30 | XMLAttribute* FindAttribute(const String& name)
31 | {
32 | for (XMLAttribute& attribute : attributes)
33 | {
34 | if (attribute.name == name)
35 | return &attribute;
36 | }
37 | return nullptr;
38 | }
39 |
40 | XMLNode* FindChild(const String& name)
41 | {
42 | for (XMLNode& child : children)
43 | {
44 | if (child.name == name)
45 | return &child;
46 | }
47 | return nullptr;
48 | }
49 | };
50 |
51 | class FL_API XMLDocument
52 | {
53 | private:
54 | String m_Filepath;
55 | XMLNode* m_RootNode;
56 | public:
57 | XMLDocument(const String& filepath);
58 | ~XMLDocument();
59 |
60 | inline XMLNode& GetRootNode() const { return *m_RootNode; }
61 | XMLNode* FindNode(const String& name);
62 | private:
63 | void ParseAllAttributes(rapidxml::xml_node<>* node, std::vector& attributes);
64 | void ParseNodeChildren(rapidxml::xml_node<>* node, XMLNode& base);
65 |
66 | XMLNode* FindChild(XMLNode& node, const String& name);
67 | };
68 |
69 | }
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/xml/rapidxml/license.txt:
--------------------------------------------------------------------------------
1 | Use of this software is granted under one of the following two licenses,
2 | to be chosen freely by the user.
3 |
4 | 1. Boost Software License - Version 1.0 - August 17th, 2003
5 | ===============================================================================
6 |
7 | Copyright (c) 2006, 2007 Marcin Kalicinski
8 |
9 | Permission is hereby granted, free of charge, to any person or organization
10 | obtaining a copy of the software and accompanying documentation covered by
11 | this license (the "Software") to use, reproduce, display, distribute,
12 | execute, and transmit the Software, and to prepare derivative works of the
13 | Software, and to permit third-parties to whom the Software is furnished to
14 | do so, all subject to the following:
15 |
16 | The copyright notices in the Software and this entire statement, including
17 | the above license grant, this restriction and the following disclaimer,
18 | must be included in all copies of the Software, in whole or in part, and
19 | all derivative works of the Software, unless such copies or derivative
20 | works are solely in the form of machine-executable object code generated by
21 | a source language processor.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 | DEALINGS IN THE SOFTWARE.
30 |
31 | 2. The MIT License
32 | ===============================================================================
33 |
34 | Copyright (c) 2006, 2007 Marcin Kalicinski
35 |
36 | Permission is hereby granted, free of charge, to any person obtaining a copy
37 | of this software and associated documentation files (the "Software"), to deal
38 | in the Software without restriction, including without limitation the rights
39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
40 | of the Software, and to permit persons to whom the Software is furnished to do so,
41 | subject to the following conditions:
42 |
43 | The above copyright notice and this permission notice shall be included in all
44 | copies or substantial portions of the Software.
45 |
46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
52 | IN THE SOFTWARE.
53 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/xml/rapidxml/rapidxml_iterators.hpp:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
2 | #define RAPIDXML_ITERATORS_HPP_INCLUDED
3 |
4 | // Copyright (C) 2006, 2009 Marcin Kalicinski
5 | // Version 1.13
6 | // Revision $DateTime: 2009/05/13 01:46:17 $
7 | //! \file rapidxml_iterators.hpp This file contains rapidxml iterators
8 |
9 | #include "rapidxml.hpp"
10 |
11 | namespace rapidxml
12 | {
13 |
14 | //! Iterator of child nodes of xml_node
15 | template
16 | class node_iterator
17 | {
18 |
19 | public:
20 |
21 | typedef typename xml_node value_type;
22 | typedef typename xml_node &reference;
23 | typedef typename xml_node *pointer;
24 | typedef std::ptrdiff_t difference_type;
25 | typedef std::bidirectional_iterator_tag iterator_category;
26 |
27 | node_iterator()
28 | : m_node(0)
29 | {
30 | }
31 |
32 | node_iterator(xml_node *node)
33 | : m_node(node->first_node())
34 | {
35 | }
36 |
37 | reference operator *() const
38 | {
39 | assert(m_node);
40 | return *m_node;
41 | }
42 |
43 | pointer operator->() const
44 | {
45 | assert(m_node);
46 | return m_node;
47 | }
48 |
49 | node_iterator& operator++()
50 | {
51 | assert(m_node);
52 | m_node = m_node->next_sibling();
53 | return *this;
54 | }
55 |
56 | node_iterator operator++(int)
57 | {
58 | node_iterator tmp = *this;
59 | ++this;
60 | return tmp;
61 | }
62 |
63 | node_iterator& operator--()
64 | {
65 | assert(m_node && m_node->previous_sibling());
66 | m_node = m_node->previous_sibling();
67 | return *this;
68 | }
69 |
70 | node_iterator operator--(int)
71 | {
72 | node_iterator tmp = *this;
73 | ++this;
74 | return tmp;
75 | }
76 |
77 | bool operator ==(const node_iterator &rhs)
78 | {
79 | return m_node == rhs.m_node;
80 | }
81 |
82 | bool operator !=(const node_iterator &rhs)
83 | {
84 | return m_node != rhs.m_node;
85 | }
86 |
87 | private:
88 |
89 | xml_node *m_node;
90 |
91 | };
92 |
93 | //! Iterator of child attributes of xml_node
94 | template
95 | class attribute_iterator
96 | {
97 |
98 | public:
99 |
100 | typedef typename xml_attribute value_type;
101 | typedef typename xml_attribute &reference;
102 | typedef typename xml_attribute *pointer;
103 | typedef std::ptrdiff_t difference_type;
104 | typedef std::bidirectional_iterator_tag iterator_category;
105 |
106 | attribute_iterator()
107 | : m_attribute(0)
108 | {
109 | }
110 |
111 | attribute_iterator(xml_node *node)
112 | : m_attribute(node->first_attribute())
113 | {
114 | }
115 |
116 | reference operator *() const
117 | {
118 | assert(m_attribute);
119 | return *m_attribute;
120 | }
121 |
122 | pointer operator->() const
123 | {
124 | assert(m_attribute);
125 | return m_attribute;
126 | }
127 |
128 | attribute_iterator& operator++()
129 | {
130 | assert(m_attribute);
131 | m_attribute = m_attribute->next_attribute();
132 | return *this;
133 | }
134 |
135 | attribute_iterator operator++(int)
136 | {
137 | attribute_iterator tmp = *this;
138 | ++this;
139 | return tmp;
140 | }
141 |
142 | attribute_iterator& operator--()
143 | {
144 | assert(m_attribute && m_attribute->previous_attribute());
145 | m_attribute = m_attribute->previous_attribute();
146 | return *this;
147 | }
148 |
149 | attribute_iterator operator--(int)
150 | {
151 | attribute_iterator tmp = *this;
152 | ++this;
153 | return tmp;
154 | }
155 |
156 | bool operator ==(const attribute_iterator &rhs)
157 | {
158 | return m_attribute == rhs.m_attribute;
159 | }
160 |
161 | bool operator !=(const attribute_iterator &rhs)
162 | {
163 | return m_attribute != rhs.m_attribute;
164 | }
165 |
166 | private:
167 |
168 | xml_attribute *m_attribute;
169 |
170 | };
171 |
172 | }
173 |
174 | #endif
175 |
--------------------------------------------------------------------------------
/Flinty/Flinty/src/fl/xml/rapidxml/rapidxml_utils.hpp:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDXML_UTILS_HPP_INCLUDED
2 | #define RAPIDXML_UTILS_HPP_INCLUDED
3 |
4 | // Copyright (C) 2006, 2009 Marcin Kalicinski
5 | // Version 1.13
6 | // Revision $DateTime: 2009/05/13 01:46:17 $
7 | //! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful
8 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.
9 |
10 | #include "rapidxml.hpp"
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | namespace rapidxml
17 | {
18 |
19 | //! Represents data loaded from a file
20 | template
21 | class file
22 | {
23 |
24 | public:
25 |
26 | //! Loads file into the memory. Data will be automatically destroyed by the destructor.
27 | //! \param filename Filename to load.
28 | file(const char *filename)
29 | {
30 | using namespace std;
31 |
32 | // Open stream
33 | basic_ifstream stream(filename, ios::binary);
34 | if (!stream)
35 | throw runtime_error(string("cannot open file ") + filename);
36 | stream.unsetf(ios::skipws);
37 |
38 | // Determine stream size
39 | stream.seekg(0, ios::end);
40 | size_t size = stream.tellg();
41 | stream.seekg(0);
42 |
43 | // Load data and add terminating 0
44 | m_data.resize(size + 1);
45 | stream.read(&m_data.front(), static_cast(size));
46 | m_data[size] = 0;
47 | }
48 |
49 | //! Loads file into the memory. Data will be automatically destroyed by the destructor
50 | //! \param stream Stream to load from
51 | file(std::basic_istream &stream)
52 | {
53 | using namespace std;
54 |
55 | // Load data and add terminating 0
56 | stream.unsetf(ios::skipws);
57 | m_data.assign(istreambuf_iterator