Added 0.6 PGE

pull/113/head
Javidx9 7 years ago committed by GitHub
parent 26997cc02d
commit bb9cfe227a
  1. 52
      olcPixelGameEngine.h

@ -2,7 +2,7 @@
olcPixelGameEngine.h olcPixelGameEngine.h
+-------------------------------------------------------------+ +-------------------------------------------------------------+
| OneLoneCoder Pixel Game Engine v0.5 | | OneLoneCoder Pixel Game Engine v0.6 |
| "Like the command prompt console one, but not..." - javidx9 | | "Like the command prompt console one, but not..." - javidx9 |
+-------------------------------------------------------------+ +-------------------------------------------------------------+
@ -292,7 +292,7 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace
// Get the state of a specific keyboard button // Get the state of a specific keyboard button
HWButton GetKey(Key k); HWButton GetKey(Key k);
// Get the state of a specific mouse button // Get the state of a specific mouse button
HWButton GetMouse(char b); HWButton GetMouse(uint32_t b);
// Get Mouse X coordinate in "pixel" space // Get Mouse X coordinate in "pixel" space
int32_t GetMouseX(); int32_t GetMouseX();
// Get Mouse Y coordinate in "pixel" space // Get Mouse Y coordinate in "pixel" space
@ -626,9 +626,11 @@ namespace olc
#ifdef _WIN32 #ifdef _WIN32
#ifdef UNICODE #ifdef UNICODE
#ifndef __MINGW32__
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
wsAppName = converter.from_bytes(sAppName); wsAppName = converter.from_bytes(sAppName);
#endif #endif
#endif
#endif #endif
// Load the default font sheet // Load the default font sheet
olc_ConstructFontSheet(); olc_ConstructFontSheet();
@ -713,7 +715,7 @@ namespace olc
return pKeyboardState[k]; return pKeyboardState[k];
} }
HWButton PixelGameEngine::GetMouse(char b) HWButton PixelGameEngine::GetMouse(uint32_t b)
{ {
return pMouseState[b]; return pMouseState[b];
} }
@ -750,7 +752,7 @@ namespace olc
if (nPixelMode == Pixel::MASK) if (nPixelMode == Pixel::MASK)
{ {
if(p.a != 255) if(p.a == 255)
pDrawTarget->SetPixel(x, y, p); pDrawTarget->SetPixel(x, y, p);
return; return;
} }
@ -1079,15 +1081,26 @@ namespace olc
void PixelGameEngine::DrawString(int32_t x, int32_t y, std::string sText) void PixelGameEngine::DrawString(int32_t x, int32_t y, std::string sText)
{ {
int32_t s = 0; int32_t sx = 0;
int32_t sy = 0;
Pixel::Mode m = nPixelMode;
SetPixelMode(Pixel::MASK);
for (auto c : sText) for (auto c : sText)
{
if (c == '\n')
{
sx = 0; sy += 8;
}
else
{ {
int32_t ox = (c - 32) % 16; int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16; int32_t oy = (c - 32) / 16;
DrawPartialSprite(x + s, y, fontSprite, ox*8, oy*8, 8, 8); DrawPartialSprite(x + sx, y + sy, fontSprite, ox * 8, oy * 8, 8, 8);
s+=8; sx += 8;
} }
} }
SetPixelMode(m);
}
void PixelGameEngine::SetPixelMode(Pixel::Mode m) void PixelGameEngine::SetPixelMode(Pixel::Mode m)
{ {
@ -1172,11 +1185,11 @@ namespace olc
} }
else if (xev.type == ButtonPress) else if (xev.type == ButtonPress)
{ {
pMouseNewState[xev.xbutton.button] = true; pMouseNewState[xev.xbutton.button-1] = true;
} }
else if (xev.type == ButtonRelease) else if (xev.type == ButtonRelease)
{ {
pMouseNewState[xev.xbutton.button] = false; pMouseNewState[xev.xbutton.button-1] = false;
} }
else if (xev.type == MotionNotify) else if (xev.type == MotionNotify)
{ {
@ -1357,7 +1370,7 @@ namespace olc
for (int i = 0; i < 24; i++) for (int i = 0; i < 24; i++)
{ {
int k = r & (1 << i) ? 255 : 0; int k = r & (1 << i) ? 255 : 0;
fontSprite->SetPixel(px, py, olc::Pixel(k, k, k)); fontSprite->SetPixel(px, py, olc::Pixel(k, k, k, k));
if (++py == 48) { px++; py = 0; } if (++py == 48) { px++; py = 0; }
} }
} }
@ -1397,10 +1410,10 @@ namespace olc
#ifdef UNICODE #ifdef UNICODE
olc_hWnd = CreateWindowEx(dwExStyle, L"OLC_PIXEL_GAME_ENGINE", L"", dwStyle, olc_hWnd = CreateWindowEx(dwExStyle, L"OLC_PIXEL_GAME_ENGINE", L"", dwStyle,
CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, GetModuleHandle(nullptr), this); 30, 30, width, height, NULL, NULL, GetModuleHandle(nullptr), this);
#else #else
olc_hWnd = CreateWindowEx(dwExStyle, "OLC_PIXEL_GAME_ENGINE", "", dwStyle, olc_hWnd = CreateWindowEx(dwExStyle, "OLC_PIXEL_GAME_ENGINE", "", dwStyle,
CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, GetModuleHandle(nullptr), this); 30, 30, width, height, NULL, NULL, GetModuleHandle(nullptr), this);
#endif #endif
// Create Keyboard Mapping // Create Keyboard Mapping
@ -1497,7 +1510,7 @@ namespace olc
olc_SetWindowAttribs.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask; olc_SetWindowAttribs.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask;
// Create the window // Create the window
olc_Window = XCreateWindow(olc_Display, olc_WindowRoot, 0, 0, nScreenWidth * nPixelWidth, nScreenHeight * nPixelHeight, 0, olc_VisualInfo->depth, InputOutput, olc_VisualInfo->visual, CWColormap | CWEventMask, &olc_SetWindowAttribs); olc_Window = XCreateWindow(olc_Display, olc_WindowRoot, 30, 30, nScreenWidth * nPixelWidth, nScreenHeight * nPixelHeight, 0, olc_VisualInfo->depth, InputOutput, olc_VisualInfo->visual, CWColormap | CWEventMask, &olc_SetWindowAttribs);
Atom wmDelete = XInternAtom(olc_Display, "WM_DELETE_WINDOW", true); Atom wmDelete = XInternAtom(olc_Display, "WM_DELETE_WINDOW", true);
XSetWMProtocols(olc_Display, olc_Window, &wmDelete, 1); XSetWMProtocols(olc_Display, olc_Window, &wmDelete, 1);
@ -1535,12 +1548,22 @@ namespace olc
{ {
glDeviceContext = glXCreateContext(olc_Display, olc_VisualInfo, nullptr, GL_TRUE); glDeviceContext = glXCreateContext(olc_Display, olc_VisualInfo, nullptr, GL_TRUE);
glXMakeCurrent(olc_Display, olc_Window, glDeviceContext); glXMakeCurrent(olc_Display, olc_Window, glDeviceContext);
XWindowAttributes gwa; XWindowAttributes gwa;
XGetWindowAttributes(olc_Display, olc_Window, &gwa); XGetWindowAttributes(olc_Display, olc_Window, &gwa);
glViewport(0, 0, gwa.width, gwa.height); glViewport(0, 0, gwa.width, gwa.height);
glSwapIntervalEXT = nullptr;
glSwapIntervalEXT = (glSwapInterval_t*)glXGetProcAddress((unsigned char*)"glXSwapIntervalEXT"); glSwapIntervalEXT = (glSwapInterval_t*)glXGetProcAddress((unsigned char*)"glXSwapIntervalEXT");
if (glSwapIntervalEXT)
glSwapIntervalEXT(olc_Display, olc_Window, 0); glSwapIntervalEXT(olc_Display, olc_Window, 0);
else
{
printf("NOTE: Could not disable VSYNC, glXSwapIntervalEXT() was not found!\n");
printf(" Don't worry though, things will still work, it's just the\n");
printf(" frame rate will be capped to your monitors refresh rate - javidx9\n");
}
return true; return true;
} }
@ -1552,3 +1575,6 @@ namespace olc
std::map<uint16_t, uint8_t> PixelGameEngine::mapKeys; std::map<uint16_t, uint8_t> PixelGameEngine::mapKeys;
//============================================================= //=============================================================
} }

Loading…
Cancel
Save