More updates to the mingw environment

This commit is contained in:
Edgaru089 2024-03-01 15:06:58 +08:00
parent edce7b8ae6
commit fcb2997e69
5 changed files with 42 additions and 12 deletions

View File

@ -1,9 +1,9 @@
If: If:
PathMatch: [.*\.h, .*\.c] PathMatch: [.*\.h, .*\.c]
CompileFlags: CompileFlags:
Add: [-xc, -I/home/edgar/Codes/JacksEscape/easyx/include, -target, x86_64-pc-windows-gnu] Add: [-xc, -DWIN32_LEAN_AND_MEAN, -I/home/edgar/Codes/JacksEscape/easyx/include, -target, x86_64-pc-windows-gnu]
--- ---
If: If:
PathMatch: [.*\.hpp, .*\.cpp] PathMatch: [.*\.hpp, .*\.cpp]
CompileFlags: CompileFlags:
Add: [-xc++, -I/home/edgar/Codes/JacksEscape/easyx/include, -target, x86_64-pc-windows-gnu] Add: [-xc++, -DWIN32_LEAN_AND_MEAN, -I/home/edgar/Codes/JacksEscape/easyx/include, -target, x86_64-pc-windows-gnu]

View File

@ -1,10 +1,17 @@
#include <graphics.h> #include <graphics.h>
#include <stdio.h>
#include "Types.h"
int main() { int main() {
TimePoint startup = time_Now();
initgraph(640, 480); initgraph(640, 480);
circle(200, 200, 100); circle(200, 200, 100);
Sleep(5000); Sleep(5000);
closegraph(); closegraph();
printf("%.6lf seconds has elapsed\n", duration_Seconds(time_Since(startup)));
return 0; return 0;
} }

View File

@ -37,7 +37,7 @@ endif
export INCLUDEFLAGS := $(Platform_INCLUDEFLAGS) export INCLUDEFLAGS := $(Platform_INCLUDEFLAGS)
export CPPFLAGS = export CPPFLAGS = -DWIN32_LEAN_AND_MEAN
export CFLAGS = $(INCLUDEFLAGS) $(BUILD_OPTIONS) -O2 -Wno-attributes -flto export CFLAGS = $(INCLUDEFLAGS) $(BUILD_OPTIONS) -O2 -Wno-attributes -flto
export CXXFLAGS = $(INCLUDEFLAGS) -DHELOS $(BUILD_OPTIONS) $(Platform_CXXFLAGS) -O2 -Wno-unused-result -flto -std=c++17 export CXXFLAGS = $(INCLUDEFLAGS) -DHELOS $(BUILD_OPTIONS) $(Platform_CXXFLAGS) -O2 -Wno-unused-result -flto -std=c++17
export LDFLAGS = $(Platform_LDFLAGS) -s -O2 -flto export LDFLAGS = $(Platform_LDFLAGS) -s -O2 -flto

26
Types.c
View File

@ -1,5 +1,6 @@
#include "Types.h" #include "Types.h"
#include <windows.h>
static inline double dmin(double x, double y) { static inline double dmin(double x, double y) {
return x < y ? x : y; return x < y ? x : y;
@ -70,9 +71,28 @@ Box2 box2_OffsetY(Box2 box, double offsetY) {
} }
Duration duration_Now() { static double freqInverse = 0.0;
// TODO Use Windows.h
TimePoint time_Now() {
// Reference: https://github.com/SFML/SFML/blob/2.6.x/src/SFML/System/Win32/ClockImpl.cpp // Reference: https://github.com/SFML/SFML/blob/2.6.x/src/SFML/System/Win32/ClockImpl.cpp
Duration d = {.microseconds = 0};
if (freqInverse == 0.0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
freqInverse = 1000000.0 / ((double)freq.QuadPart);
}
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
TimePoint t = {.microseconds = (int64_t)(((double)time.QuadPart) * freqInverse)};
return t;
}
Duration time_Since(TimePoint prev) {
return time_Difference(time_Now(), prev);
}
Duration time_Difference(TimePoint now, TimePoint prev) {
Duration d = {.microseconds = now.microseconds - prev.microseconds};
return d; return d;
} }

15
Types.h
View File

@ -40,17 +40,20 @@ Box2 box2_OffsetY(Box2 box, double offsetY);
// Time duration. // Time duration.
typedef struct { typedef struct {
uint64_t microseconds; int64_t microseconds;
} Duration; } Duration;
static inline double duration_Seconds(const Duration t) { return ((double)t.microseconds) / 1000.0 / 1000.0; } static inline double duration_Seconds(const Duration t) { return ((double)t.microseconds) / 1000.0 / 1000.0; }
static inline double duration_Milliseconds(const Duration t) { return ((double)t.microseconds) / 1000.0; } static inline double duration_Milliseconds(const Duration t) { return ((double)t.microseconds) / 1000.0; }
// Returns a relative duration since // A Time point since the start of the program.
// a static time point in the past. typedef struct {
// int64_t microseconds;
// Its absolute value has no meaning. } TimePoint;
Duration duration_Now();
TimePoint time_Now();
Duration time_Since(TimePoint prev);
Duration time_Difference(TimePoint now, TimePoint prev);
#ifdef __cplusplus #ifdef __cplusplus