VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
global.cpp
Go to the documentation of this file.
1#include "pch_mm.h"
2#include "global.hpp"
3#ifndef _WIN32
4#ifdef __APPLE__
5#include <sys/time.h>
6#else
7#define _XOPEN_SOURCE 700
8#include <time.h>
9#endif
10#endif
11
12
13
14
15
16
17int killme = 0;
18int sys_width = 1980; /* dimensions of default screen */
19int sys_height = 1200;
20float sys_dpi = 1.0;
21int vid_width = 1280; /* dimensions of our part of the screen */
22int vid_height = 720;
23int mouse_x = 0;
24int mouse_y = 0;
25int mickey_x = 0;
26int mickey_y = 0;
27char mouse[8] = { 0,0,0,0,0,0,0,0 };
29
30
34#ifdef _WIN32
35
36uint64_t sys_ticksecond = 1000;
37static uint64_t sys_time_start = 0;
38uint64_t sys_time(void)
39{
40 uint64_t now;
41 QueryPerformanceCounter((LARGE_INTEGER*)&now);
42 return now - sys_time_start;
43}
44
45void sys_time_init(void)
46{
47 QueryPerformanceFrequency((LARGE_INTEGER*)&sys_ticksecond);
48 QueryPerformanceCounter((LARGE_INTEGER*)&sys_time_start);
49}
50
51#else // Mac & Linux versions are identical
52
53
54uint64_t sys_ticksecond = 1000000000;
55static uint64_t sys_time_start = 0;
56uint64_t sys_time(void)
57{
58 struct timespec ts;
59 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
60 return ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec) - sys_time_start;
61}
62
63void sys_time_init(void)
64{
65 struct timespec ts;
66 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
67 sys_time_start = (uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
68}
69#endif
70
74
75#ifdef _WIN32
76void sys_browser(wchar_t* url)
77{
78
79 //ShellExecute(NULL, L"open", url, NULL, NULL, SW_SHOWNORMAL);
80}
81
82#elif defined __APPLE__
83#include <objc/objc.h>
84#include <objc/runtime.h>
85#include <objc/message.h>
86void sys_browser(char* url)
87{
88 // NSURL *MyNSURL = [NSURL URLWithString:[NSString stringWithUTF8String:url]];
89 // [[NSWorkspace sharedWorkspace] openURL:MyNSURL];
90 SEL URLWithString = sel_registerName("URLWithString:");
91 SEL stringWithUTF8String = sel_registerName("stringWithUTF8String:");
92 SEL sharedWorkspace = sel_registerName("sharedWorkspace");
93 SEL openURL = sel_registerName("openURL:");
94 Class NSURL = objc_getClass("NSURL");
95 Class NSString = objc_getClass("NSString");
96 Class NSWorkspace = objc_getClass("NSWorkspace");
97 id url_nsstring = ((id(*)(Class, SEL, char*))objc_msgSend)(NSString, stringWithUTF8String, url);
98 id ns_url = ((id(*)(Class, SEL, id))objc_msgSend)(NSURL, URLWithString, url_nsstring);
99 id workspace = ((id(*)(Class, SEL))objc_msgSend)(NSWorkspace, sharedWorkspace);
100 ((id(*)(id, SEL, id))objc_msgSend)(workspace, openURL, ns_url);
101}
102
103#else // linux version
104#include <string.h>
105#include <stdio.h>
106#include <stdlib.h>
107void sys_browser(char* url)
108{
109 int c = 1000;
110 char buf[c];
111 memset(buf, 0, sizeof(char) * c);
112 snprintf(buf, c, "sensible-browser %s &", url);
113 system(buf);
114}
115#endif
116
117/*
118
119#define SYS_EVENT_MAX 256
120struct sys_event sys_events[SYS_EVENT_MAX];
121uint32_t sys_event_in = 0;
122uint32_t sys_event_out = 0;
123
124void sys_event_init(void)
125{
126 sys_event_in = 0;
127 sys_event_out = 0;
128}
129
130int sys_event_read(struct sys_event* event)
131{
132 if (sys_event_in == sys_event_out)return 0;
133
134 sys_event_out++;
135 if (sys_event_out == SYS_EVENT_MAX)
136 {
137 sys_event_out = 0;
138 }
139 *event = sys_events[sys_event_out];
140 return 1;
141}
142
143int sys_event_write(struct sys_event event)
144{
145 if (sys_event_in == (sys_event_out - 1)) return 0;
146
147 if ((sys_event_in == (SYS_EVENT_MAX - 1)) &&
148 sys_event_out == 0) return 0;
149
150 sys_event_in++;
151 if (sys_event_in == SYS_EVENT_MAX)
152 {
153 sys_event_in = 0;
154 }
155
156 sys_events[sys_event_in] = event;
157 return 1;
158}
159
160*/
161
162/*
163
164uint16_t sys_key_modifiers(void)
165{
166 uint16_t modifiers = 0;
167 if (keys[KEY_LSHIFT]) {
168 modifiers |= (KEY_MOD_SHIFT | KEY_MOD_LSHIFT);
169 }
170 if (keys[KEY_RSHIFT]) {
171 modifiers |= (KEY_MOD_SHIFT | KEY_MOD_RSHIFT);
172 }
173 if (keys[KEY_LALT]) {
174 modifiers |= (KEY_MOD_ALT | KEY_MOD_LALT);
175 }
176 if (keys[KEY_RALT]) {
177 modifiers |= (KEY_MOD_ALT | KEY_MOD_RALT);
178 }
179 if (keys[KEY_LCONTROL]) {
180 modifiers |= (KEY_MOD_CTRL | KEY_MOD_LCTRL);
181 }
182 if (keys[KEY_RCONTROL]) {
183 modifiers |= (KEY_MOD_CTRL | KEY_MOD_RCTRL);
184 }
185 if (keys[KEY_LLOGO]) {
186 modifiers |= (KEY_MOD_LOGO | KEY_MOD_LLOGO);
187 }
188 if (keys[KEY_RLOGO]) {
189 modifiers |= (KEY_MOD_LOGO | KEY_MOD_RLOGO);
190 }
191 if (keys[KEY_MENU]) {
192 modifiers |= KEY_MOD_MENU;
193 }
194 return modifiers;
195}
196
197*/
void sys_browser(char *url)
Definition: global.cpp:107
void sys_time_init(void)
Definition: global.cpp:63
int sys_width
Definition: global.cpp:18
int vid_width
Definition: global.cpp:21
int mickey_y
Definition: global.cpp:26
int killme
Definition: global.cpp:17
uint64_t sys_time(void)
Definition: global.cpp:56
int mickey_x
Definition: global.cpp:25
int mouse_x
Definition: global.cpp:23
char mouse[8]
Definition: global.cpp:27
uint64_t sys_ticksecond
Definition: global.cpp:54
int mouse_y
Definition: global.cpp:24
char keys[KEYMAX]
Definition: global.cpp:28
int sys_height
Definition: global.cpp:19
int vid_height
Definition: global.cpp:22
float sys_dpi
Definition: global.cpp:20
#define KEYMAX
Definition: global.hpp:9