Source/Gorgon/Main.cpp

Tue, 06 Jul 2021 10:22:49 +0300

author
cemkalyoncu
date
Tue, 06 Jul 2021 10:22:49 +0300
branch
4.x-dev
changeset 1701
b168349a931d
parent 1584
4606aeb9823a
child 1728
92bb193f0a6e
permissions
-rw-r--r--

* Image/Bitmap rotate

764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
1 #include <thread>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
2
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
3 #include "Main.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
4
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
5 #include "Filesystem.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
6 #include "WindowManager.h"
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
7 #include "Window.h"
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
8 #include "OS.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
9 #include "Time.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
10 #include "Animation.h"
797
5d31c4836303 * Loader for Resource::Data
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 789
diff changeset
11 #include "Resource.h"
811
e6af71f983cc * Pulse audio connection
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 797
diff changeset
12 #include "Audio.h"
1578
fff352023162 #14 Wav files can now be streamed
cemkalyoncu
parents: 1577
diff changeset
13 #include "Multimedia.h"
863
c6321c51594e * Fixed fullscreen support for windows
cemkalyoncu
parents: 839
diff changeset
14 #include "Graphics.h"
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
15
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
16 #ifdef SCRIPTING
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
17 # include "Scripting.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
18 #endif
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
19
1387
2e91fa117d0f * Widget registry
cemkalyoncu
parents: 1379
diff changeset
20 #ifdef ENABLE_UI
2e91fa117d0f * Widget registry
cemkalyoncu
parents: 1379
diff changeset
21 # include "UI.h"
2e91fa117d0f * Widget registry
cemkalyoncu
parents: 1379
diff changeset
22 #endif
1236
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
23
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
24 /**
1416
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
25 * @page programminghelpers Programming Utilities
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
26 *
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
27 * Debugging Help
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
28 * ==============
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
29 *
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
30 * GDB Pretty Printing
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
31 * -------------------
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
32 *
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
33 * For GDB pretty printing to work with Gorgon objects simply copy `Resource/Gorgon-gdb.py`
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
34 * file to the startup directory of your program. You may need to allow script execution
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
35 * in GDB, when GDB is run, it will show you options on how to allow autoload scripts.
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
36 *
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
37 * Adding the following to `~/.gdbinit` will allow script autoload in everywhere:
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
38 *
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
39 * @code
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
40 * set auto-load safe-path /
ce292ba2937c * DataEffect tests
cemkalyoncu
parents: 1387
diff changeset
41 * @endcode
1236
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
42 */
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
43
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
44 #ifdef __GNUC__
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
45 //For GDB pretty printing
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
46 #define DEFINE_GDB_SCRIPT(name) \
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
47 asm("\
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
48 .pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n\
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
49 .byte 1\n\
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
50 .asciz \"" name "\"\n\
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
51 .popsection \n\
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
52 ");
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
53
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
54 DEFINE_GDB_SCRIPT ("Gorgon-gdb.py")
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
55 #endif
1816e647b817 * Polyfill problem is fixed for AA>1 cases
cemkalyoncu
parents: 928
diff changeset
56
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
57 namespace Gorgon {
789
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
58
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
59 Event<> BeforeFrameEvent;
1288
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
60
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
61 std::vector<std::function<void()>> once;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
62
928
c46672472f39 * Audio now joins its thread
cemkalyoncu
parents: 909
diff changeset
63 bool exiting = false;
c46672472f39 * Audio now joins its thread
cemkalyoncu
parents: 909
diff changeset
64
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
65 namespace internal {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
66 std::string systemname;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
67 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
68
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
69 namespace Animation {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
70 void Animate();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
71 }
1577
78a9e4944144 * Design for streaming audio class
cemkalyoncu
parents: 1523
diff changeset
72
78a9e4944144 * Design for streaming audio class
cemkalyoncu
parents: 1523
diff changeset
73 void gorgon_exit() {
78a9e4944144 * Design for streaming audio class
cemkalyoncu
parents: 1523
diff changeset
74 exiting = true;
78a9e4944144 * Design for streaming audio class
cemkalyoncu
parents: 1523
diff changeset
75 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
76
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
77 void Initialize(const std::string &name) {
1577
78a9e4944144 * Design for streaming audio class
cemkalyoncu
parents: 1523
diff changeset
78 atexit(&gorgon_exit);
78a9e4944144 * Design for streaming audio class
cemkalyoncu
parents: 1523
diff changeset
79
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
80 internal::systemname=name;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
81
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
82 Filesystem::Initialize();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
83 WindowManager::Initialize();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
84
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
85 #ifdef SCRIPTING
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
86 Scripting::Initialize();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
87 #endif
839
ddfaef71313f * Current state of the graphics module is done
cemkalyoncu
parents: 811
diff changeset
88 #ifdef AUDIO
811
e6af71f983cc * Pulse audio connection
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 797
diff changeset
89 Audio::Initialize();
839
ddfaef71313f * Current state of the graphics module is done
cemkalyoncu
parents: 811
diff changeset
90 #endif
1578
fff352023162 #14 Wav files can now be streamed
cemkalyoncu
parents: 1577
diff changeset
91 Multimedia::Initialize();
797
5d31c4836303 * Loader for Resource::Data
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 789
diff changeset
92 Resource::Initialize();
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
93 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
94
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
95 void Tick() {
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
96 static bool inited=false;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
97 auto ctime=Time::GetTime();
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
98 if(!inited) {
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
99 Time::internal::framestart=ctime;
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
100 inited=true;
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
101 }
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
102
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
103 Time::internal::deltatime=ctime-Time::internal::framestart;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
104 Time::internal::framestart=ctime;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
105
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
106 Animation::Animate();
1288
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
107
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
108 for(auto &fn : once) {
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
109 fn();
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
110 }
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
111
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
112 once.clear();
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
113 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
114
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
115 void Render() {
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
116 for(auto &w : Window::Windows) {
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
117 w.Render();
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
118 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
119 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
120
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
121 void NextFrame() {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
122 Render();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
123
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
124 auto ctime=Time::GetTime();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
125 auto currentdelta=ctime-Time::FrameStart();
1324
eb8d1585e8ec * Several bug fixes
cemkalyoncu
parents: 1288
diff changeset
126
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
127 if(currentdelta<16) {
909
7fd61951afa1 * Fixed shaders
cemkalyoncu
parents: 863
diff changeset
128 std::this_thread::sleep_for(std::chrono::duration<unsigned long, std::milli>(15-currentdelta));
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
129 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
130
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
131 Tick();
789
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
132
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
133 BeforeFrameEvent();
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
134
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
135 OS::processmessages();
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
136 }
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
137
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
138 void UpdateFrame() {
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
139 Render();
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
140
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
141 Tick();
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
142
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
143 BeforeFrameEvent();
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
144
4de9ca4d7da0 * HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 784
diff changeset
145 OS::processmessages();
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
146 }
1288
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
147
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
148 void RegisterOnce(std::function<void()> fn) {
1379
0c9e6ca3674b * IconButton now resizes automatically if no size is given
cemkalyoncu
parents: 1324
diff changeset
149 once.push_back(fn);
1288
27ad8c8a1fa8 * Press/Release events for buttons
cemkalyoncu
parents: 1236
diff changeset
150 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
151 }

mercurial