-
Notifications
You must be signed in to change notification settings - Fork 0
/
olcPixelGameEngine.h
6376 lines (5499 loc) · 226 KB
/
olcPixelGameEngine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef OLC_PGE_DEF
#define OLC_PGE_DEF
#pragma region std_includes
// O------------------------------------------------------------------------------O
// | STANDARD INCLUDES |
// O------------------------------------------------------------------------------O
#include <cmath>
#include <cstdint>
#include <string>
#include <iostream>
#include <streambuf>
#include <sstream>
#include <chrono>
#include <vector>
#include <list>
#include <thread>
#include <atomic>
#include <fstream>
#include <map>
#include <functional>
#include <algorithm>
#include <array>
#include <cstring>
#pragma endregion
#define PGE_VER 225
// O------------------------------------------------------------------------------O
// | COMPILER CONFIGURATION ODDITIES |
// O------------------------------------------------------------------------------O
#pragma region compiler_config
#define USE_EXPERIMENTAL_FS
#if defined(_WIN32)
#if _MSC_VER >= 1920 && _MSVC_LANG >= 201703L
#undef USE_EXPERIMENTAL_FS
#endif
#endif
#if defined(__linux__) || defined(__MINGW32__) || defined(__EMSCRIPTEN__) || defined(__FreeBSD__) || defined(__APPLE__)
#if __cplusplus >= 201703L
#undef USE_EXPERIMENTAL_FS
#endif
#endif
#if !defined(OLC_KEYBOARD_UK)
#define OLC_KEYBOARD_UK
#endif
#if defined(USE_EXPERIMENTAL_FS) || defined(FORCE_EXPERIMENTAL_FS)
// C++14
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
namespace _gfs = std::experimental::filesystem::v1;
#else
// C++17
#include <filesystem>
namespace _gfs = std::filesystem;
#endif
#if defined(UNICODE) || defined(_UNICODE)
#define olcT(s) L##s
#else
#define olcT(s) s
#endif
#define UNUSED(x) (void)(x)
// O------------------------------------------------------------------------------O
// | PLATFORM SELECTION CODE, Thanks slavka! |
// O------------------------------------------------------------------------------O
#if defined(OLC_PGE_HEADLESS)
#define OLC_PLATFORM_HEADLESS
#define OLC_GFX_HEADLESS
#if !defined(OLC_IMAGE_STB) && !defined(OLC_IMAGE_GDI) && !defined(OLC_IMAGE_LIBPNG)
#define OLC_IMAGE_HEADLESS
#endif
#endif
// Platform
#if !defined(OLC_PLATFORM_WINAPI) && !defined(OLC_PLATFORM_X11) && !defined(OLC_PLATFORM_GLUT) && !defined(OLC_PLATFORM_EMSCRIPTEN) && !defined(OLC_PLATFORM_HEADLESS)
#if !defined(OLC_PLATFORM_CUSTOM_EX)
#if defined(_WIN32)
#define OLC_PLATFORM_WINAPI
#endif
#if defined(__linux__) || defined(__FreeBSD__)
#define OLC_PLATFORM_X11
#endif
#if defined(__APPLE__)
#define GL_SILENCE_DEPRECATION
#define OLC_PLATFORM_GLUT
#endif
#if defined(__EMSCRIPTEN__)
#define OLC_PLATFORM_EMSCRIPTEN
#endif
#endif
#endif
// Start Situation
#if defined(OLC_PLATFORM_GLUT) || defined(OLC_PLATFORM_EMSCRIPTEN)
#define PGE_USE_CUSTOM_START
#endif
// Renderer
#if !defined(OLC_GFX_OPENGL10) && !defined(OLC_GFX_OPENGL33) && !defined(OLC_GFX_DIRECTX10) && !defined(OLC_GFX_HEADLESS)
#if !defined(OLC_GFX_CUSTOM_EX)
#if defined(OLC_PLATFORM_EMSCRIPTEN)
#define OLC_GFX_OPENGL33
#else
#define OLC_GFX_OPENGL10
#endif
#endif
#endif
// Image loader
#if !defined(OLC_IMAGE_STB) && !defined(OLC_IMAGE_GDI) && !defined(OLC_IMAGE_LIBPNG) && !defined(OLC_IMAGE_HEADLESS)
#if !defined(OLC_IMAGE_CUSTOM_EX)
#if defined(_WIN32)
#define OLC_IMAGE_GDI
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__)
#define OLC_IMAGE_LIBPNG
#endif
#endif
#endif
// O------------------------------------------------------------------------------O
// | PLATFORM-SPECIFIC DEPENDENCIES |
// O------------------------------------------------------------------------------O
#if !defined(OLC_PGE_HEADLESS)
#if defined(OLC_PLATFORM_WINAPI)
#define _WINSOCKAPI_ // Thanks Cornchipss
#if !defined(VC_EXTRALEAN)
#define VC_EXTRALEAN
#endif
#if !defined(NOMINMAX)
#define NOMINMAX
#endif
// In Code::Blocks
#if !defined(_WIN32_WINNT)
#ifdef HAVE_MSMF
#define _WIN32_WINNT 0x0600 // Windows Vista
#else
#define _WIN32_WINNT 0x0500 // Windows 2000
#endif
#endif
#include <windows.h>
#undef _WINSOCKAPI_
#endif
#if defined(OLC_PLATFORM_X11)
namespace X11
{
#include <X11/X.h>
#include <X11/Xlib.h>
}
#endif
#if defined(OLC_PLATFORM_GLUT)
#if defined(__linux__)
#include <GL/glut.h>
#include <GL/freeglut_ext.h>
#endif
#if defined(__APPLE__)
#include <GLUT/glut.h>
#include <objc/message.h>
#include <objc/NSObjCRuntime.h>
#endif
#endif
#endif
#if defined(OLC_PGE_HEADLESS)
#if defined max
#undef max
#endif
#if defined min
#undef min
#endif
#endif
#pragma endregion
// O------------------------------------------------------------------------------O
// | olcPixelGameEngine INTERFACE DECLARATION |
// O------------------------------------------------------------------------------O
#pragma region pge_declaration
namespace olc
{
class PixelGameEngine;
class Sprite;
// Pixel Game Engine Advanced Configuration
constexpr uint8_t nMouseButtons = 5;
constexpr uint8_t nDefaultAlpha = 0xFF;
constexpr uint32_t nDefaultPixel = (nDefaultAlpha << 24);
constexpr uint8_t nTabSizeInSpaces = 4;
constexpr size_t OLC_MAX_VERTS = 128;
enum rcode { FAIL = 0, OK = 1, NO_FILE = -1 };
// O------------------------------------------------------------------------------O
// | olc::Pixel - Represents a 32-Bit RGBA colour |
// O------------------------------------------------------------------------------O
#if !defined(OLC_IGNORE_PIXEL)
struct Pixel
{
union
{
uint32_t n = nDefaultPixel;
struct { uint8_t r; uint8_t g; uint8_t b; uint8_t a; };
};
enum Mode { NORMAL, MASK, ALPHA, CUSTOM };
Pixel();
Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = nDefaultAlpha);
Pixel(uint32_t p);
Pixel& operator = (const Pixel& v) = default;
bool operator ==(const Pixel& p) const;
bool operator !=(const Pixel& p) const;
Pixel operator * (const float i) const;
Pixel operator / (const float i) const;
Pixel& operator *=(const float i);
Pixel& operator /=(const float i);
Pixel operator + (const Pixel& p) const;
Pixel operator - (const Pixel& p) const;
Pixel& operator +=(const Pixel& p);
Pixel& operator -=(const Pixel& p);
Pixel operator * (const Pixel& p) const;
Pixel& operator *=(const Pixel& p);
Pixel inv() const;
};
Pixel PixelF(float red, float green, float blue, float alpha = 1.0f);
Pixel PixelLerp(const olc::Pixel& p1, const olc::Pixel& p2, float t);
// O------------------------------------------------------------------------------O
// | USEFUL CONSTANTS |
// O------------------------------------------------------------------------------O
static const Pixel
GREY(192, 192, 192), DARK_GREY(128, 128, 128), VERY_DARK_GREY(64, 64, 64),
RED(255, 0, 0), DARK_RED(128, 0, 0), VERY_DARK_RED(64, 0, 0),
YELLOW(255, 255, 0), DARK_YELLOW(128, 128, 0), VERY_DARK_YELLOW(64, 64, 0),
GREEN(0, 255, 0), DARK_GREEN(0, 128, 0), VERY_DARK_GREEN(0, 64, 0),
CYAN(0, 255, 255), DARK_CYAN(0, 128, 128), VERY_DARK_CYAN(0, 64, 64),
BLUE(0, 0, 255), DARK_BLUE(0, 0, 128), VERY_DARK_BLUE(0, 0, 64),
MAGENTA(255, 0, 255), DARK_MAGENTA(128, 0, 128), VERY_DARK_MAGENTA(64, 0, 64),
WHITE(255, 255, 255), BLACK(0, 0, 0), BLANK(0, 0, 0, 0);
#endif
// Thanks to scripticuk and others for updating the key maps
// NOTE: The GLUT platform will need updating, open to contributions ;)
enum Key
{
NONE,
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
K0, K1, K2, K3, K4, K5, K6, K7, K8, K9,
F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
UP, DOWN, LEFT, RIGHT,
SPACE, TAB, SHIFT, CTRL, INS, DEL, HOME, END, PGUP, PGDN,
BACK, ESCAPE, RETURN, ENTER, PAUSE, SCROLL,
NP0, NP1, NP2, NP3, NP4, NP5, NP6, NP7, NP8, NP9,
NP_MUL, NP_DIV, NP_ADD, NP_SUB, NP_DECIMAL, PERIOD,
EQUALS, COMMA, MINUS,
OEM_1, OEM_2, OEM_3, OEM_4, OEM_5, OEM_6, OEM_7, OEM_8,
CAPS_LOCK, ENUM_END
};
namespace Mouse
{
static constexpr int32_t LEFT = 0;
static constexpr int32_t RIGHT = 1;
static constexpr int32_t MIDDLE = 2;
};
// O------------------------------------------------------------------------------O
// | olc::HWButton - Represents the state of a hardware button (mouse/key/joy) |
// O------------------------------------------------------------------------------O
struct HWButton
{
bool bPressed = false; // Set once during the frame the event occurs
bool bReleased = false; // Set once during the frame the event occurs
bool bHeld = false; // Set true for all frames between pressed and released events
};
// O------------------------------------------------------------------------------O
// | olc::vX2d - A generic 2D vector type |
// O------------------------------------------------------------------------------O
#if !defined(OLC_IGNORE_VEC2D)
template <class T>
struct v2d_generic
{
T x = 0;
T y = 0;
v2d_generic() : x(0), y(0) {}
v2d_generic(T _x, T _y) : x(_x), y(_y) {}
v2d_generic(const v2d_generic& v) : x(v.x), y(v.y) {}
v2d_generic& operator=(const v2d_generic& v) = default;
T mag() const { return T(std::sqrt(x * x + y * y)); }
T mag2() const { return x * x + y * y; }
v2d_generic norm() const { T r = 1 / mag(); return v2d_generic(x * r, y * r); }
v2d_generic perp() const { return v2d_generic(-y, x); }
v2d_generic floor() const { return v2d_generic(std::floor(x), std::floor(y)); }
v2d_generic ceil() const { return v2d_generic(std::ceil(x), std::ceil(y)); }
v2d_generic max(const v2d_generic& v) const { return v2d_generic(std::max(x, v.x), std::max(y, v.y)); }
v2d_generic min(const v2d_generic& v) const { return v2d_generic(std::min(x, v.x), std::min(y, v.y)); }
v2d_generic cart() { return { std::cos(y) * x, std::sin(y) * x }; }
v2d_generic polar() { return { mag(), std::atan2(y, x) }; }
v2d_generic clamp(const v2d_generic& v1, const v2d_generic& v2) const { return this->max(v1).min(v2); }
v2d_generic lerp(const v2d_generic& v1, const double t) { return this->operator*(T(1.0 - t)) + (v1 * T(t)); }
T dot(const v2d_generic& rhs) const { return this->x * rhs.x + this->y * rhs.y; }
T cross(const v2d_generic& rhs) const { return this->x * rhs.y - this->y * rhs.x; }
v2d_generic operator + (const v2d_generic& rhs) const { return v2d_generic(this->x + rhs.x, this->y + rhs.y); }
v2d_generic operator - (const v2d_generic& rhs) const { return v2d_generic(this->x - rhs.x, this->y - rhs.y); }
v2d_generic operator * (const T& rhs) const { return v2d_generic(this->x * rhs, this->y * rhs); }
v2d_generic operator * (const v2d_generic& rhs) const { return v2d_generic(this->x * rhs.x, this->y * rhs.y); }
v2d_generic operator / (const T& rhs) const { return v2d_generic(this->x / rhs, this->y / rhs); }
v2d_generic operator / (const v2d_generic& rhs) const { return v2d_generic(this->x / rhs.x, this->y / rhs.y); }
v2d_generic& operator += (const v2d_generic& rhs) { this->x += rhs.x; this->y += rhs.y; return *this; }
v2d_generic& operator -= (const v2d_generic& rhs) { this->x -= rhs.x; this->y -= rhs.y; return *this; }
v2d_generic& operator *= (const T& rhs) { this->x *= rhs; this->y *= rhs; return *this; }
v2d_generic& operator /= (const T& rhs) { this->x /= rhs; this->y /= rhs; return *this; }
v2d_generic& operator *= (const v2d_generic& rhs) { this->x *= rhs.x; this->y *= rhs.y; return *this; }
v2d_generic& operator /= (const v2d_generic& rhs) { this->x /= rhs.x; this->y /= rhs.y; return *this; }
v2d_generic operator + () const { return { +x, +y }; }
v2d_generic operator - () const { return { -x, -y }; }
bool operator == (const v2d_generic& rhs) const { return (this->x == rhs.x && this->y == rhs.y); }
bool operator != (const v2d_generic& rhs) const { return (this->x != rhs.x || this->y != rhs.y); }
const std::string str() const { return std::string("(") + std::to_string(this->x) + "," + std::to_string(this->y) + ")"; }
friend std::ostream& operator << (std::ostream& os, const v2d_generic& rhs) { os << rhs.str(); return os; }
operator v2d_generic<int32_t>() const { return { static_cast<int32_t>(this->x), static_cast<int32_t>(this->y) }; }
operator v2d_generic<float>() const { return { static_cast<float>(this->x), static_cast<float>(this->y) }; }
operator v2d_generic<double>() const { return { static_cast<double>(this->x), static_cast<double>(this->y) }; }
};
// Note: joshinils has some good suggestions here, but they are complicated to implement at this moment,
// however they will appear in a future version of PGE
template<class T> inline v2d_generic<T> operator * (const float& lhs, const v2d_generic<T>& rhs)
{ return v2d_generic<T>((T)(lhs * (float)rhs.x), (T)(lhs * (float)rhs.y)); }
template<class T> inline v2d_generic<T> operator * (const double& lhs, const v2d_generic<T>& rhs)
{ return v2d_generic<T>((T)(lhs * (double)rhs.x), (T)(lhs * (double)rhs.y)); }
template<class T> inline v2d_generic<T> operator * (const int& lhs, const v2d_generic<T>& rhs)
{ return v2d_generic<T>((T)(lhs * (int)rhs.x), (T)(lhs * (int)rhs.y)); }
template<class T> inline v2d_generic<T> operator / (const float& lhs, const v2d_generic<T>& rhs)
{ return v2d_generic<T>((T)(lhs / (float)rhs.x), (T)(lhs / (float)rhs.y)); }
template<class T> inline v2d_generic<T> operator / (const double& lhs, const v2d_generic<T>& rhs)
{ return v2d_generic<T>((T)(lhs / (double)rhs.x), (T)(lhs / (double)rhs.y)); }
template<class T> inline v2d_generic<T> operator / (const int& lhs, const v2d_generic<T>& rhs)
{ return v2d_generic<T>((T)(lhs / (int)rhs.x), (T)(lhs / (int)rhs.y)); }
// To stop dandistine crying...
template<class T, class U> inline bool operator < (const v2d_generic<T>& lhs, const v2d_generic<U>& rhs)
{ return lhs.y < rhs.y || (lhs.y == rhs.y && lhs.x < rhs.x); }
template<class T, class U> inline bool operator > (const v2d_generic<T>& lhs, const v2d_generic<U>& rhs)
{ return lhs.y > rhs.y || (lhs.y == rhs.y && lhs.x > rhs.x); }
typedef v2d_generic<int32_t> vi2d;
typedef v2d_generic<uint32_t> vu2d;
typedef v2d_generic<float> vf2d;
typedef v2d_generic<double> vd2d;
#endif
// O------------------------------------------------------------------------------O
// | olc::ResourcePack - A virtual scrambled filesystem to pack your assets into |
// O------------------------------------------------------------------------------O
struct ResourceBuffer : public std::streambuf
{
ResourceBuffer(std::ifstream& ifs, uint32_t offset, uint32_t size);
std::vector<char> vMemory;
};
class ResourcePack : public std::streambuf
{
public:
ResourcePack();
~ResourcePack();
bool AddFile(const std::string& sFile);
bool LoadPack(const std::string& sFile, const std::string& sKey);
bool SavePack(const std::string& sFile, const std::string& sKey);
ResourceBuffer GetFileBuffer(const std::string& sFile);
bool Loaded();
private:
struct sResourceFile { uint32_t nSize; uint32_t nOffset; };
std::map<std::string, sResourceFile> mapFiles;
std::ifstream baseFile;
std::vector<char> scramble(const std::vector<char>& data, const std::string& key);
std::string makeposix(const std::string& path);
};
class ImageLoader
{
public:
ImageLoader() = default;
virtual ~ImageLoader() = default;
virtual olc::rcode LoadImageResource(olc::Sprite* spr, const std::string& sImageFile, olc::ResourcePack* pack) = 0;
virtual olc::rcode SaveImageResource(olc::Sprite* spr, const std::string& sImageFile) = 0;
};
// O------------------------------------------------------------------------------O
// | olc::Sprite - An image represented by a 2D array of olc::Pixel |
// O------------------------------------------------------------------------------O
class Sprite
{
public:
Sprite();
Sprite(const std::string& sImageFile, olc::ResourcePack* pack = nullptr);
Sprite(int32_t w, int32_t h);
Sprite(const olc::Sprite&) = delete;
~Sprite();
public:
olc::rcode LoadFromFile(const std::string& sImageFile, olc::ResourcePack* pack = nullptr);
public:
int32_t width = 0;
int32_t height = 0;
enum Mode { NORMAL, PERIODIC, CLAMP };
enum Flip { NONE = 0, HORIZ = 1, VERT = 2 };
public:
void SetSampleMode(olc::Sprite::Mode mode = olc::Sprite::Mode::NORMAL);
Pixel GetPixel(int32_t x, int32_t y) const;
bool SetPixel(int32_t x, int32_t y, Pixel p);
Pixel GetPixel(const olc::vi2d& a) const;
bool SetPixel(const olc::vi2d& a, Pixel p);
Pixel Sample(float x, float y) const;
Pixel Sample(const olc::vf2d& uv) const;
Pixel SampleBL(float u, float v) const;
Pixel SampleBL(const olc::vf2d& uv) const;
Pixel* GetData();
olc::Sprite* Duplicate();
olc::Sprite* Duplicate(const olc::vi2d& vPos, const olc::vi2d& vSize);
olc::vi2d Size() const;
std::vector<olc::Pixel> pColData;
Mode modeSample = Mode::NORMAL;
static std::unique_ptr<olc::ImageLoader> loader;
};
// O------------------------------------------------------------------------------O
// | olc::Decal - A GPU resident storage of an olc::Sprite |
// O------------------------------------------------------------------------------O
class Decal
{
public:
Decal(olc::Sprite* spr, bool filter = false, bool clamp = true);
Decal(const uint32_t nExistingTextureResource, olc::Sprite* spr);
virtual ~Decal();
void Update();
void UpdateSprite();
public: // But dont touch
int32_t id = -1;
olc::Sprite* sprite = nullptr;
olc::vf2d vUVScale = { 1.0f, 1.0f };
};
enum class DecalMode
{
NORMAL,
ADDITIVE,
MULTIPLICATIVE,
STENCIL,
ILLUMINATE,
WIREFRAME,
};
enum class DecalStructure
{
LINE,
FAN,
STRIP,
LIST
};
// O------------------------------------------------------------------------------O
// | olc::Renderable - Convenience class to keep a sprite and decal together |
// O------------------------------------------------------------------------------O
class Renderable
{
public:
Renderable() = default;
Renderable(Renderable&& r) : pSprite(std::move(r.pSprite)), pDecal(std::move(r.pDecal)) {}
Renderable(const Renderable&) = delete;
olc::rcode Load(const std::string& sFile, ResourcePack* pack = nullptr, bool filter = false, bool clamp = true);
void Create(uint32_t width, uint32_t height, bool filter = false, bool clamp = true);
olc::Decal* Decal() const;
olc::Sprite* Sprite() const;
private:
std::unique_ptr<olc::Sprite> pSprite = nullptr;
std::unique_ptr<olc::Decal> pDecal = nullptr;
};
// O------------------------------------------------------------------------------O
// | Auxilliary components internal to engine |
// O------------------------------------------------------------------------------O
struct DecalInstance
{
olc::Decal* decal = nullptr;
std::vector<olc::vf2d> pos;
std::vector<olc::vf2d> uv;
std::vector<float> w;
std::vector<float> z;
std::vector<olc::Pixel> tint;
olc::DecalMode mode = olc::DecalMode::NORMAL;
olc::DecalStructure structure = olc::DecalStructure::FAN;
uint32_t points = 0;
bool depth = false;
};
struct LayerDesc
{
olc::vf2d vOffset = { 0, 0 };
olc::vf2d vScale = { 1, 1 };
bool bShow = false;
bool bUpdate = false;
olc::Renderable pDrawTarget;
uint32_t nResID = 0;
std::vector<DecalInstance> vecDecalInstance;
olc::Pixel tint = olc::WHITE;
std::function<void()> funcHook = nullptr;
};
class Renderer
{
public:
virtual ~Renderer() = default;
virtual void PrepareDevice() = 0;
virtual olc::rcode CreateDevice(std::vector<void*> params, bool bFullScreen, bool bVSYNC) = 0;
virtual olc::rcode DestroyDevice() = 0;
virtual void DisplayFrame() = 0;
virtual void PrepareDrawing() = 0;
virtual void SetDecalMode(const olc::DecalMode& mode) = 0;
virtual void DrawLayerQuad(const olc::vf2d& offset, const olc::vf2d& scale, const olc::Pixel tint) = 0;
virtual void DrawDecal(const olc::DecalInstance& decal) = 0;
virtual uint32_t CreateTexture(const uint32_t width, const uint32_t height, const bool filtered = false, const bool clamp = true) = 0;
virtual void UpdateTexture(uint32_t id, olc::Sprite* spr) = 0;
virtual void ReadTexture(uint32_t id, olc::Sprite* spr) = 0;
virtual uint32_t DeleteTexture(const uint32_t id) = 0;
virtual void ApplyTexture(uint32_t id) = 0;
virtual void UpdateViewport(const olc::vi2d& pos, const olc::vi2d& size) = 0;
virtual void ClearBuffer(olc::Pixel p, bool bDepth) = 0;
static olc::PixelGameEngine* ptrPGE;
};
class Platform
{
public:
virtual ~Platform() = default;
virtual olc::rcode ApplicationStartUp() = 0;
virtual olc::rcode ApplicationCleanUp() = 0;
virtual olc::rcode ThreadStartUp() = 0;
virtual olc::rcode ThreadCleanUp() = 0;
virtual olc::rcode CreateGraphics(bool bFullScreen, bool bEnableVSYNC, const olc::vi2d& vViewPos, const olc::vi2d& vViewSize) = 0;
virtual olc::rcode CreateWindowPane(const olc::vi2d& vWindowPos, olc::vi2d& vWindowSize, bool bFullScreen) = 0;
virtual olc::rcode SetWindowTitle(const std::string& s) = 0;
virtual olc::rcode StartSystemEventLoop() = 0;
virtual olc::rcode HandleSystemEvent() = 0;
static olc::PixelGameEngine* ptrPGE;
};
class PGEX;
// The Static Twins (plus one)
static std::unique_ptr<Renderer> renderer;
static std::unique_ptr<Platform> platform;
static std::map<size_t, uint8_t> mapKeys;
// O------------------------------------------------------------------------------O
// | olc::PixelGameEngine - The main BASE class for your application |
// O------------------------------------------------------------------------------O
class PixelGameEngine
{
public:
PixelGameEngine();
virtual ~PixelGameEngine();
public:
olc::rcode Construct(int32_t screen_w, int32_t screen_h, int32_t pixel_w, int32_t pixel_h,
bool full_screen = false, bool vsync = false, bool cohesion = false);
olc::rcode Start();
public: // User Override Interfaces
// Called once on application startup, use to load your resources
virtual bool OnUserCreate();
// Called every frame, and provides you with a time per frame value
virtual bool OnUserUpdate(float fElapsedTime);
// Called once on application termination, so you can be one clean coder
virtual bool OnUserDestroy();
// Called when a text entry is confirmed with "enter" key
virtual void OnTextEntryComplete(const std::string& sText);
// Called when a console command is executed
virtual bool OnConsoleCommand(const std::string& sCommand);
public: // Hardware Interfaces
// Returns true if window is currently in focus
bool IsFocused() const;
// Get the state of a specific keyboard button
HWButton GetKey(Key k) const;
// Get the state of a specific mouse button
HWButton GetMouse(uint32_t b) const;
// Get Mouse X coordinate in "pixel" space
int32_t GetMouseX() const;
// Get Mouse Y coordinate in "pixel" space
int32_t GetMouseY() const;
// Get Mouse Wheel Delta
int32_t GetMouseWheel() const;
// Get the mouse in window space
const olc::vi2d& GetWindowMouse() const;
// Gets the mouse as a vector to keep Tarriest happy
const olc::vi2d& GetMousePos() const;
static const std::map<size_t, uint8_t>& GetKeyMap() { return mapKeys; }
public: // Utility
// Returns the width of the screen in "pixels"
int32_t ScreenWidth() const;
// Returns the height of the screen in "pixels"
int32_t ScreenHeight() const;
// Returns the width of the currently selected drawing target in "pixels"
int32_t GetDrawTargetWidth() const;
// Returns the height of the currently selected drawing target in "pixels"
int32_t GetDrawTargetHeight() const;
// Returns the currently active draw target
olc::Sprite* GetDrawTarget() const;
// Resize the primary screen sprite
void SetScreenSize(int w, int h);
// Specify which Sprite should be the target of drawing functions, use nullptr
// to specify the primary screen
void SetDrawTarget(Sprite* target);
// Gets the current Frames Per Second
uint32_t GetFPS() const;
// Gets last update of elapsed time
float GetElapsedTime() const;
// Gets Actual Window size
const olc::vi2d& GetWindowSize() const;
// Gets pixel scale
const olc::vi2d& GetPixelSize() const;
// Gets actual pixel scale
const olc::vi2d& GetScreenPixelSize() const;
// Gets "screen" size
const olc::vi2d& GetScreenSize() const;
// Gets any files dropped this frame
const std::vector<std::string>& GetDroppedFiles() const;
const olc::vi2d& GetDroppedFilesPoint() const;
public: // CONFIGURATION ROUTINES
// Layer targeting functions
void SetDrawTarget(uint8_t layer, bool bDirty = true);
void EnableLayer(uint8_t layer, bool b);
void SetLayerOffset(uint8_t layer, const olc::vf2d& offset);
void SetLayerOffset(uint8_t layer, float x, float y);
void SetLayerScale(uint8_t layer, const olc::vf2d& scale);
void SetLayerScale(uint8_t layer, float x, float y);
void SetLayerTint(uint8_t layer, const olc::Pixel& tint);
void SetLayerCustomRenderFunction(uint8_t layer, std::function<void()> f);
std::vector<LayerDesc>& GetLayers();
uint32_t CreateLayer();
// Change the pixel mode for different optimisations
// olc::Pixel::NORMAL = No transparency
// olc::Pixel::MASK = Transparent if alpha is < 255
// olc::Pixel::ALPHA = Full transparency
void SetPixelMode(Pixel::Mode m);
Pixel::Mode GetPixelMode();
// Use a custom blend function
void SetPixelMode(std::function<olc::Pixel(const int x, const int y, const olc::Pixel& pSource, const olc::Pixel& pDest)> pixelMode);
// Change the blend factor from between 0.0f to 1.0f;
void SetPixelBlend(float fBlend);
public: // DRAWING ROUTINES
// Draws a single Pixel
virtual bool Draw(int32_t x, int32_t y, Pixel p = olc::WHITE);
bool Draw(const olc::vi2d& pos, Pixel p = olc::WHITE);
// Draws a line from (x1,y1) to (x2,y2)
void DrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, Pixel p = olc::WHITE, uint32_t pattern = 0xFFFFFFFF);
void DrawLine(const olc::vi2d& pos1, const olc::vi2d& pos2, Pixel p = olc::WHITE, uint32_t pattern = 0xFFFFFFFF);
// Draws a circle located at (x,y) with radius
void DrawCircle(int32_t x, int32_t y, int32_t radius, Pixel p = olc::WHITE, uint8_t mask = 0xFF);
void DrawCircle(const olc::vi2d& pos, int32_t radius, Pixel p = olc::WHITE, uint8_t mask = 0xFF);
// Fills a circle located at (x,y) with radius
void FillCircle(int32_t x, int32_t y, int32_t radius, Pixel p = olc::WHITE);
void FillCircle(const olc::vi2d& pos, int32_t radius, Pixel p = olc::WHITE);
// Draws a rectangle at (x,y) to (x+w,y+h)
void DrawRect(int32_t x, int32_t y, int32_t w, int32_t h, Pixel p = olc::WHITE);
void DrawRect(const olc::vi2d& pos, const olc::vi2d& size, Pixel p = olc::WHITE);
// Fills a rectangle at (x,y) to (x+w,y+h)
void FillRect(int32_t x, int32_t y, int32_t w, int32_t h, Pixel p = olc::WHITE);
void FillRect(const olc::vi2d& pos, const olc::vi2d& size, Pixel p = olc::WHITE);
// Draws a triangle between points (x1,y1), (x2,y2) and (x3,y3)
void DrawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, Pixel p = olc::WHITE);
void DrawTriangle(const olc::vi2d& pos1, const olc::vi2d& pos2, const olc::vi2d& pos3, Pixel p = olc::WHITE);
// Flat fills a triangle between points (x1,y1), (x2,y2) and (x3,y3)
void FillTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, Pixel p = olc::WHITE);
void FillTriangle(const olc::vi2d& pos1, const olc::vi2d& pos2, const olc::vi2d& pos3, Pixel p = olc::WHITE);
// Fill a textured and coloured triangle
void FillTexturedTriangle(std::vector<olc::vf2d> vPoints, std::vector<olc::vf2d> vTex, std::vector<olc::Pixel> vColour, olc::Sprite* sprTex);
void FillTexturedPolygon(const std::vector<olc::vf2d>& vPoints, const std::vector<olc::vf2d>& vTex, const std::vector<olc::Pixel>& vColour, olc::Sprite* sprTex, olc::DecalStructure structure = olc::DecalStructure::LIST);
// Draws an entire sprite at location (x,y)
void DrawSprite(int32_t x, int32_t y, Sprite* sprite, uint32_t scale = 1, uint8_t flip = olc::Sprite::NONE);
void DrawSprite(const olc::vi2d& pos, Sprite* sprite, uint32_t scale = 1, uint8_t flip = olc::Sprite::NONE);
// Draws an area of a sprite at location (x,y), where the
// selected area is (ox,oy) to (ox+w,oy+h)
void DrawPartialSprite(int32_t x, int32_t y, Sprite* sprite, int32_t ox, int32_t oy, int32_t w, int32_t h, uint32_t scale = 1, uint8_t flip = olc::Sprite::NONE);
void DrawPartialSprite(const olc::vi2d& pos, Sprite* sprite, const olc::vi2d& sourcepos, const olc::vi2d& size, uint32_t scale = 1, uint8_t flip = olc::Sprite::NONE);
// Draws a single line of text - traditional monospaced
void DrawString(int32_t x, int32_t y, const std::string& sText, Pixel col = olc::WHITE, uint32_t scale = 1);
void DrawString(const olc::vi2d& pos, const std::string& sText, Pixel col = olc::WHITE, uint32_t scale = 1);
olc::vi2d GetTextSize(const std::string& s);
// Draws a single line of text - non-monospaced
void DrawStringProp(int32_t x, int32_t y, const std::string& sText, Pixel col = olc::WHITE, uint32_t scale = 1);
void DrawStringProp(const olc::vi2d& pos, const std::string& sText, Pixel col = olc::WHITE, uint32_t scale = 1);
olc::vi2d GetTextSizeProp(const std::string& s);
// Decal Quad functions
void SetDecalMode(const olc::DecalMode& mode);
void SetDecalStructure(const olc::DecalStructure& structure);
// Draws a whole decal, with optional scale and tinting
void DrawDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE);
// Draws a region of a decal, with optional scale and tinting
void DrawPartialDecal(const olc::vf2d& pos, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE);
void DrawPartialDecal(const olc::vf2d& pos, const olc::vf2d& size, olc::Decal* decal, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE);
// Draws fully user controlled 4 vertices, pos(pixels), uv(pixels), colours
void DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements = 4);
// Draws a decal with 4 arbitrary points, warping the texture to look "correct"
void DrawWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::Pixel& tint = olc::WHITE);
void DrawWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::Pixel& tint = olc::WHITE);
void DrawWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::Pixel& tint = olc::WHITE);
// As above, but you can specify a region of a decal source sprite
void DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d(&pos)[4], const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE);
void DrawPartialWarpedDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE);
void DrawPartialWarpedDecal(olc::Decal* decal, const std::array<olc::vf2d, 4>& pos, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::Pixel& tint = olc::WHITE);
// Draws a decal rotated to specified angle, wit point of rotation offset
void DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE);
void DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f, 1.0f }, const olc::Pixel& tint = olc::WHITE);
// Draws a multiline string as a decal, with tiniting and scaling
void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
// Draws a single shaded filled rectangle as a decal
void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
// Draws a corner shaded rectangle as a decal
void GradientFillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel colTL, const olc::Pixel colBL, const olc::Pixel colBR, const olc::Pixel colTR);
// Draws an arbitrary convex textured polygon using GPU
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const olc::Pixel tint = olc::WHITE);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const olc::Pixel tint = olc::WHITE);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& tint);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint);
void DrawPolygonDecal(olc::Decal* decal, const std::vector<olc::vf2d>& pos, const std::vector<float>& depth, const std::vector<olc::vf2d>& uv, const std::vector<olc::Pixel>& colours, const olc::Pixel tint);
// Draws a line in Decal Space
void DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p = olc::WHITE);
void DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawRotatedStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
// Clears entire draw target to Pixel
void Clear(Pixel p);
// Clears the rendering back buffer
void ClearBuffer(Pixel p, bool bDepth = true);
// Returns the font image
olc::Sprite* GetFontSprite();
// Clip a line segment to visible area
bool ClipLineToScreen(olc::vi2d& in_p1, olc::vi2d& in_p2);
// Dont allow PGE to mark layers as dirty, so pixel graphics don't update
void EnablePixelTransfer(const bool bEnable = true);
// Command Console Routines
void ConsoleShow(const olc::Key &keyExit, bool bSuspendTime = true);
bool IsConsoleShowing() const;
void ConsoleClear();
std::stringstream& ConsoleOut();
void ConsoleCaptureStdOut(const bool bCapture);
// Text Entry Routines
void TextEntryEnable(const bool bEnable, const std::string& sText = "");
std::string TextEntryGetString() const;
int32_t TextEntryGetCursor() const;
bool IsTextEntryEnabled() const;
private:
void UpdateTextEntry();
void UpdateConsole();
public:
// Experimental Lightweight 3D Routines ================
#ifdef OLC_ENABLE_EXPERIMENTAL
// Set Manual View Matrix
void LW3D_View(const std::array<float, 16>& m);
// Set Manual World Matrix
void LW3D_World(const std::array<float, 16>& m);
// Set Manual Projection Matrix
void LW3D_Projection(const std::array<float, 16>& m);
// Draws a vector of vertices, interprted as individual triangles
void LW3D_DrawTriangles(olc::Decal* decal, const std::vector<std::array<float,3>>& pos, const std::vector<olc::vf2d>& tex, const std::vector<olc::Pixel>& col);
void LW3D_DrawWarpedDecal(olc::Decal* decal, const std::vector<std::array<float, 3>>& pos, const olc::Pixel& tint);
void LW3D_ModelTranslate(const float x, const float y, const float z);
// Camera convenience functions
void LW3D_SetCameraAtTarget(const float fEyeX, const float fEyeY, const float fEyeZ,
const float fTargetX, const float fTargetY, const float fTargetZ,
const float fUpX = 0.0f, const float fUpY = 1.0f, const float fUpZ = 0.0f);
void LW3D_SetCameraAlongDirection(const float fEyeX, const float fEyeY, const float fEyeZ,
const float fDirX, const float fDirY, const float fDirZ,
const float fUpX = 0.0f, const float fUpY = 1.0f, const float fUpZ = 0.0f);
// 3D Rendering Flags
void LW3D_EnableDepthTest(const bool bEnableDepth);
void LW3D_EnableBackfaceCulling(const bool bEnableCull);
#endif
public: // Branding
std::string sAppName;
private: // Inner mysterious workings
olc::Sprite* pDrawTarget = nullptr;
Pixel::Mode nPixelMode = Pixel::NORMAL;
float fBlendFactor = 1.0f;
olc::vi2d vScreenSize = { 256, 240 };
olc::vf2d vInvScreenSize = { 1.0f / 256.0f, 1.0f / 240.0f };
olc::vi2d vPixelSize = { 4, 4 };
olc::vi2d vScreenPixelSize = { 4, 4 };
olc::vi2d vMousePos = { 0, 0 };
int32_t nMouseWheelDelta = 0;
olc::vi2d vMousePosCache = { 0, 0 };
olc::vi2d vMouseWindowPos = { 0, 0 };
int32_t nMouseWheelDeltaCache = 0;
olc::vi2d vWindowSize = { 0, 0 };
olc::vi2d vViewPos = { 0, 0 };
olc::vi2d vViewSize = { 0,0 };
bool bFullScreen = false;
olc::vf2d vPixel = { 1.0f, 1.0f };
bool bHasInputFocus = false;
bool bHasMouseFocus = false;
bool bEnableVSYNC = false;
float fFrameTimer = 1.0f;
float fLastElapsed = 0.0f;
int nFrameCount = 0;
bool bSuspendTextureTransfer = false;
Renderable fontRenderable;
std::vector<LayerDesc> vLayers;
uint8_t nTargetLayer = 0;
uint32_t nLastFPS = 0;
bool bPixelCohesion = false;
DecalMode nDecalMode = DecalMode::NORMAL;
DecalStructure nDecalStructure = DecalStructure::FAN;
std::function<olc::Pixel(const int x, const int y, const olc::Pixel&, const olc::Pixel&)> funcPixelMode;
std::chrono::time_point<std::chrono::system_clock> m_tp1, m_tp2;
std::vector<olc::vi2d> vFontSpacing;
std::vector<std::string> vDroppedFiles;
std::vector<std::string> vDroppedFilesCache;
olc::vi2d vDroppedFilesPoint;
olc::vi2d vDroppedFilesPointCache;
// Command Console Specific
bool bConsoleShow = false;
bool bConsoleSuspendTime = false;
olc::Key keyConsoleExit = olc::Key::F1;
std::stringstream ssConsoleOutput;
std::streambuf* sbufOldCout = nullptr;
olc::vi2d vConsoleSize;
olc::vi2d vConsoleCursor = { 0,0 };
olc::vf2d vConsoleCharacterScale = { 1.0f, 2.0f };
std::vector<std::string> sConsoleLines;
std::list<std::string> sCommandHistory;
std::list<std::string>::iterator sCommandHistoryIt;
// Text Entry Specific
bool bTextEntryEnable = false;
std::string sTextEntryString = "";
int32_t nTextEntryCursor = 0;
std::vector<std::tuple<olc::Key, std::string, std::string>> vKeyboardMap;
// State of keyboard
bool pKeyNewState[256] = { 0 };
bool pKeyOldState[256] = { 0 };
HWButton pKeyboardState[256] = { 0 };
// State of mouse
bool pMouseNewState[nMouseButtons] = { 0 };
bool pMouseOldState[nMouseButtons] = { 0 };
HWButton pMouseState[nMouseButtons] = { 0 };
// The main engine thread
void EngineThread();
// If anything sets this flag to false, the engine
// "should" shut down gracefully
static std::atomic<bool> bAtomActive;
public:
// "Break In" Functions
void olc_UpdateMouse(int32_t x, int32_t y);
void olc_UpdateMouseWheel(int32_t delta);
void olc_UpdateWindowSize(int32_t x, int32_t y);
void olc_UpdateViewport();
void olc_ConstructFontSheet();
void olc_CoreUpdate();
void olc_PrepareEngine();
void olc_UpdateMouseState(int32_t button, bool state);
void olc_UpdateKeyState(int32_t key, bool state);
void olc_UpdateMouseFocus(bool state);
void olc_UpdateKeyFocus(bool state);
void olc_Terminate();
void olc_DropFiles(int32_t x, int32_t y, const std::vector<std::string>& vFiles);
void olc_Reanimate();
bool olc_IsRunning();
// At the very end of this file, chooses which
// components to compile
virtual void olc_ConfigureSystem();
// NOTE: Items Here are to be deprecated, I have left them in for now
// in case you are using them, but they will be removed.
// olc::vf2d vSubPixelOffset = { 0.0f, 0.0f };
public: // PGEX Stuff
friend class PGEX;
void pgex_Register(olc::PGEX* pgex);
private:
std::vector<olc::PGEX*> vExtensions;
};
// O------------------------------------------------------------------------------O
// | PGE EXTENSION BASE CLASS - Permits access to PGE functions from extension |
// O------------------------------------------------------------------------------O
class PGEX
{
friend class olc::PixelGameEngine;
public:
PGEX(bool bHook = false);
protected:
virtual void OnBeforeUserCreate();
virtual void OnAfterUserCreate();
virtual bool OnBeforeUserUpdate(float &fElapsedTime);
virtual void OnAfterUserUpdate(float fElapsedTime);
protected:
static PixelGameEngine* pge;
};
}
#pragma endregion
#pragma region opengl33_iface
// In order to facilitate more advanced graphics features, some PGEX
// will rely on shaders. Instead of having each PGEX responsible for
// managing this, for convenience, this interface exists.
#if defined(OLC_GFX_OPENGL33)
#if defined(OLC_PLATFORM_WINAPI)
#include <gl/GL.h>
#define CALLSTYLE __stdcall
#endif
#if defined(__linux__) || defined(__FreeBSD__)
#include <GL/gl.h>
#endif
#if defined(OLC_PLATFORM_X11)
namespace X11 {
#include <GL/glx.h>
}
#define CALLSTYLE
#endif