Skip to content

Commit 0f54bea

Browse files
committed
Merge branch 'master' of https://github.com/ivansafrin/Polycode
2 parents 887581d + 60873b7 commit 0f54bea

File tree

23 files changed

+172
-37
lines changed

23 files changed

+172
-37
lines changed

Assets/Templates/C++/Windows/PolycodeTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
1212

1313
MSG Msg;
1414
do {
15-
if(PeekMessage(&Msg, NULL, 0,0,PM_REMOVE)) {
15+
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
1616
TranslateMessage(&Msg);
1717
DispatchMessage(&Msg);
1818
}

Core/Contents/Include/PolyEntity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ namespace Polycode {
393393
* Returns the entity's rotation as euler angles
394394
@return Entity's rotation as euler angles
395395
*/
396-
Vector3 getEulerRotation() const;
396+
Vector3 getRotationEuler() const;
397397

398398
/**
399399
* Returns the entity's pitch combined with the combined pitch of its parent.

Core/Contents/Include/PolyLogger.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,25 @@ namespace Polycode {
6363
* @param str The c-string to log
6464
*/
6565
static void logw(const char *str);
66+
67+
void setLogToFile(bool val);
68+
bool getLogToFile();
69+
70+
/**
71+
* @return The file that is logged to
72+
*/
73+
FILE *getLogFile();
74+
75+
/**
76+
* @return The logger instance
77+
*/
78+
static Logger *getInstance();
79+
80+
protected:
81+
FILE *logFile;
82+
bool logToFile;
83+
84+
private:
85+
static Logger *overrideInstance;
6686
};
6787
}

Core/Contents/Include/PolySDLCore.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ namespace Polycode {
4949
void enableMouse(bool newval);
5050
void captureMouse(bool);
5151
unsigned int getTicks();
52-
bool Update();
52+
bool systemUpdate();
5353
void Render();
54-
void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel);
54+
void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport = true);
5555
void createThread(Threaded *target);
5656
std::vector<Rectangle> getVideoModes();
5757

@@ -68,6 +68,7 @@ namespace Polycode {
6868
void removeDiskItem(const String& itemPath);
6969
String openFolderPicker();
7070
std::vector<String> openFilePicker(std::vector<CoreFileExtension> extensions, bool allowMultiple);
71+
String saveFilePicker(std::vector<CoreFileExtension> extensions);
7172
void resizeTo(int xRes, int yRes);
7273

7374
String executeExternalCommand(String command, String args, String inDirectory="");

Core/Contents/Source/PolyCoreServices.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void CoreServices::setupBasicListeners() {
122122
}
123123

124124
CoreServices::CoreServices() : EventDispatcher() {
125-
logger = new Logger();
125+
logger = Logger::getInstance();
126126
resourceManager = new ResourceManager();
127127
config = new Config();
128128
materialManager = new MaterialManager();

Core/Contents/Source/PolyEntity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ Vector3 Entity::getScale() const {
709709
return scale;
710710
}
711711

712-
Vector3 Entity::getEulerRotation() const {
712+
Vector3 Entity::getRotationEuler() const {
713713
return rotation;
714714
}
715715

Core/Contents/Source/PolyLogger.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@
2424
#ifdef _MSC_VER
2525
#include <windows.h>
2626
#endif
27+
#include "PolyLogger.h"
2728
#include <stdio.h>
2829
#include <stdarg.h>
2930
#include <string>
3031
#include <iostream>
32+
#include <time.h>
3133

3234
using namespace Polycode;
3335

36+
Logger* Logger::overrideInstance = NULL;
37+
3438
LoggerEvent::LoggerEvent(String message) : Event() {
3539
this->message = message;
3640
}
@@ -41,11 +45,12 @@ LoggerEvent::~LoggerEvent() {
4145

4246

4347
Logger::Logger() : EventDispatcher() {
44-
48+
logToFile = false;
49+
logFile = fopen("poly.log", "w");
4550
}
4651

4752
Logger::~Logger() {
48-
53+
fclose(logFile);
4954
}
5055

5156
void Logger::logBroadcast(String message) {
@@ -62,6 +67,12 @@ void Logger::log(const char *format, ...) {
6267
va_start(args, format);
6368
vfprintf(stderr, format, args);
6469
va_end(args);
70+
71+
if (Logger::getInstance()->getLogToFile()){
72+
va_start(args, format);
73+
vfprintf(Logger::getInstance()->getLogFile(), format, args);
74+
va_end(args);
75+
}
6576

6677
#ifdef _MSC_VER
6778
#ifdef _DEBUG
@@ -84,3 +95,37 @@ void Logger::log(const char *format, ...) {
8495
#endif
8596

8697
}
98+
99+
void Logger::setLogToFile(bool val){
100+
if (!logToFile && val){
101+
time_t t = time(NULL);
102+
char mbstr[100];
103+
if (strftime(mbstr, sizeof(mbstr), "%y_%m_%d.log", localtime(&t))) {
104+
//if (logFile)
105+
// fclose(logFile);
106+
logFile = fopen((const char*)mbstr, "w");
107+
} else {
108+
logFile = fopen("poly.log", "w");
109+
}
110+
}
111+
112+
logToFile = val;
113+
}
114+
115+
bool Logger::getLogToFile(){
116+
return logToFile;
117+
}
118+
119+
FILE *Logger::getLogFile(){
120+
return logFile;
121+
}
122+
123+
Logger *Logger::getInstance(){
124+
if (overrideInstance) {
125+
return overrideInstance;
126+
}
127+
128+
overrideInstance = new Logger;
129+
//Logger::log("Creating new logger instance...\n");
130+
return overrideInstance;
131+
}

Core/Contents/Source/PolySDLCore.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ SDLCore::SDLCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen, bool
133133
CoreServices::getInstance()->installModule(new GLSLShaderModule());
134134
}
135135

136-
void SDLCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) {
136+
void SDLCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport) {
137137
this->xRes = xRes;
138138
this->yRes = yRes;
139139
this->fullScreen = fullScreen;
@@ -313,7 +313,7 @@ void SDLCore::Render() {
313313
SDL_GL_SwapBuffers();
314314
}
315315

316-
bool SDLCore::Update() {
316+
bool SDLCore::systemUpdate() {
317317
if(!running)
318318
return false;
319319
doSleep();
@@ -499,6 +499,11 @@ vector<String> SDLCore::openFilePicker(vector<CoreFileExtension> extensions, boo
499499
return r;
500500
}
501501

502+
String SDLCore::saveFilePicker(std::vector<CoreFileExtension> extensions) {
503+
String r = "";
504+
return r;
505+
}
506+
502507
void SDLCore::resizeTo(int xRes, int yRes) {
503508
renderer->Resize(xRes, yRes);
504509
}

Core/Contents/Source/PolyWinCore.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,27 @@ void Win32Core::enableMouse(bool newval) {
162162
void Win32Core::captureMouse(bool newval) {
163163
// Capture the mouse in the window holding
164164
// our polycode screen.
165-
SetCapture(hWnd);
165+
if (newval){
166+
RECT rect;
167+
GetWindowRect(core->hWnd, &rect);
168+
169+
RECT crect;
170+
RECT arect;
171+
172+
GetClientRect(core->hWnd, &crect);
173+
arect = crect;
174+
AdjustWindowRectEx(&arect, WS_CAPTION | WS_BORDER, FALSE, 0);
175+
176+
rect.left += (crect.left - arect.left);
177+
rect.right += (crect.right - arect.right);
178+
rect.top += (crect.top - arect.top);
179+
rect.bottom += (crect.bottom - arect.bottom);
180+
181+
ClipCursor(&rect);
182+
}
183+
else {
184+
ClipCursor(NULL);
185+
}
166186

167187
Core::captureMouse(newval);
168188
}
@@ -193,6 +213,7 @@ void Win32Core::Render() {
193213
bool Win32Core::systemUpdate() {
194214
if(!running)
195215
return false;
216+
captureMouse(Core::mouseCaptured);
196217
doSleep();
197218
checkEvents();
198219
Gamepad_processEvents();

Examples/C++/Build/Windows/PolycodeExamples/PolycodeExample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
1212

1313
MSG Msg;
1414
do {
15-
if(PeekMessage(&Msg, NULL, 0,0,PM_REMOVE)) {
15+
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
1616
TranslateMessage(&Msg);
1717
DispatchMessage(&Msg);
1818
}

0 commit comments

Comments
 (0)