Skip to content

Commit 8529fdc

Browse files
committed
Merging in linux changes by gamaral.
1 parent 10be10c commit 8529fdc

13 files changed

+420
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Build

Build/.keep

Whitespace-only changes.

CMakeLists.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
project(Monocle)
2+
cmake_minimum_required(VERSION 2.6.0)
3+
if(COMMAND cmake_policy)
4+
cmake_policy(SET CMP0003 NEW)
5+
endif(COMMAND cmake_policy)
6+
7+
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
8+
9+
include_directories(AFTER SYSTEM ${PROJECT_BINARY_DIR} Code)
10+
11+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
12+
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
13+
14+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
15+
16+
set(BUILD_TESTS OFF CACHE BOOL "Build tests")
17+
set(WITH_OPENAL ON CACHE BOOL "Use OpenAL")
18+
set(WITH_OPENGL ON CACHE BOOL "Use OpenGL")
19+
20+
if(WIN32)
21+
add_definitions(-DMONOCLE_WINDOWS)
22+
set(WINDOWS ON)
23+
endif(WIN32)
24+
25+
if (APPLE)
26+
add_definitions(-DMONOCLE_APPLE)
27+
set(MACOSX ON)
28+
set(APPLE ON)
29+
endif(APPLE)
30+
31+
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
32+
find_package(X11 REQUIRED)
33+
add_definitions(-DMONOCLE_LINUX)
34+
set(LINUX ON)
35+
endif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
36+
37+
if(WITH_OPENGL)
38+
find_package(OpenGL REQUIRED)
39+
add_definitions(-DMONOCLE_OPENGL)
40+
endif(WITH_OPENGL)
41+
42+
if(WITH_OPENAL)
43+
find_package(OpenAL REQUIRED)
44+
add_definitions(-DMONOCLE_OPENAL)
45+
endif(WITH_OPENAL)
46+
47+
add_subdirectory(Code)
48+

Code/CMakeLists.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
file(GLOB CORE_SRCS *.cpp)
2+
file(GLOB COLLIDERS_SRCS Colliders/*.cpp)
3+
file(GLOB OPENAL_SRCS OpenAL/*.cpp)
4+
file(GLOB OPENGL_SRCS OpenGL/*.cpp OpenGL/glpng/*.c OpenGL/glpng/*/*.c)
5+
6+
set(CORE_LINK ${CORE_LINK} ${OPENGL_LIBRARIES} ${OPENAL_LIBRARY})
7+
8+
if(WINDOWS)
9+
file(GLOB WINDOWS_SRCS Windows/*.cpp)
10+
set(PLATFORM_SRCS ${PLATFORM_SRCS} ${WINDOWS_SRCS})
11+
endif(WINDOWS)
12+
13+
if(LINUX)
14+
include_directories(${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR})
15+
set(CORE_LINK ${CORE_LINK} ${X11_LIBRARIES})
16+
file(GLOB LINUX_SRCS Linux/*.cpp)
17+
set(PLATFORM_SRCS ${PLATFORM_SRCS} ${LINUX_SRCS})
18+
endif(LINUX)
19+
20+
add_library(MonocleCore
21+
${CORE_SRCS}
22+
${COLLIDERS_SRCS}
23+
${PLATFORM_SRCS}
24+
${OPENAL_SRCS}
25+
${OPENGL_SRCS}
26+
)
27+
28+
# TODO: Add proper dependency handling
29+
target_link_libraries(MonocleCore ${CORE_LINK})
30+
31+
add_subdirectory(Tests)
32+

Code/Collision.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "Collision.h"
2+
3+
#include <stdio.h>
4+
25
#include "Entity.h"
36

47
namespace Monocle

Code/Linux/LinuxPlatform.cpp

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
#ifdef MONOCLE_LINUX
2+
3+
#include "LinuxPlatform.h"
4+
5+
#include<X11/X.h>
6+
#include<X11/extensions/Xrandr.h>
7+
8+
#include <stdio.h>
9+
#include <time.h>
10+
#include <unistd.h>
11+
12+
#include "../Debug.h"
13+
#include "../Core.h"
14+
#include "../Graphics.h"
15+
16+
// opengl/windows init code baesd on http://nehe.gamedev.net
17+
// keyboard code based on SDL http://www.libsdl.org/
18+
19+
#ifndef VK_0
20+
#define VK_0 '0'
21+
#define VK_1 '1'
22+
#define VK_2 '2'
23+
#define VK_3 '3'
24+
#define VK_4 '4'
25+
#define VK_5 '5'
26+
#define VK_6 '6'
27+
#define VK_7 '7'
28+
#define VK_8 '8'
29+
#define VK_9 '9'
30+
#define VK_A 'A'
31+
#define VK_B 'B'
32+
#define VK_C 'C'
33+
#define VK_D 'D'
34+
#define VK_E 'E'
35+
#define VK_F 'F'
36+
#define VK_G 'G'
37+
#define VK_H 'H'
38+
#define VK_I 'I'
39+
#define VK_J 'J'
40+
#define VK_K 'K'
41+
#define VK_L 'L'
42+
#define VK_M 'M'
43+
#define VK_N 'N'
44+
#define VK_O 'O'
45+
#define VK_P 'P'
46+
#define VK_Q 'Q'
47+
#define VK_R 'R'
48+
#define VK_S 'S'
49+
#define VK_T 'T'
50+
#define VK_U 'U'
51+
#define VK_V 'V'
52+
#define VK_W 'W'
53+
#define VK_X 'X'
54+
#define VK_Y 'Y'
55+
#define VK_Z 'Z'
56+
#endif /* VK_0 */
57+
58+
#define VK_SEMICOLON 0xBA
59+
#define VK_EQUALS 0xBB
60+
#define VK_COMMA 0xBC
61+
#define VK_MINUS 0xBD
62+
#define VK_PERIOD 0xBE
63+
#define VK_SLASH 0xBF
64+
#define VK_GRAVE 0xC0
65+
#define VK_LBRACKET 0xDB
66+
#define VK_BACKSLASH 0xDC
67+
#define VK_RBRACKET 0xDD
68+
#define VK_APOSTROPHE 0xDE
69+
#define VK_BACKTICK 0xDF
70+
#define VK_OEM_102 0xE2
71+
72+
#define REPEATED_KEYMASK (1<<30)
73+
#define EXTENDED_KEYMASK (1<<24)
74+
75+
namespace Monocle
76+
{
77+
LinuxPlatform *LinuxPlatform::instance = NULL;
78+
79+
//TODO: cleanup code, replace message boxes
80+
bool LinuxPlatform::CreatePlatformWindow(const char* title, int width, int height, int bits, bool fullscreenflag)
81+
{
82+
const char *windowName = "Monocle Engine\0";
83+
Window hRootWindow;
84+
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, bits, GLX_DOUBLEBUFFER, None };
85+
XVisualInfo *vi;
86+
Colormap cmap;
87+
XSetWindowAttributes swa;
88+
89+
fullscreen=fullscreenflag; // Set The Global Fullscreen Flag
90+
91+
hDisplay = XOpenDisplay(NULL);
92+
if (hDisplay == NULL) {
93+
fprintf(stderr, "Cannot open display\n");
94+
return(false);
95+
}
96+
97+
hRootWindow = DefaultRootWindow(hDisplay);
98+
hScreen = DefaultScreen(hDisplay);
99+
100+
vi = glXChooseVisual(hDisplay, 0, att);
101+
102+
if(vi == NULL) {
103+
fprintf(stderr, "No visual was found.\n");
104+
return(false);
105+
}
106+
cmap = XCreateColormap(hDisplay, hRootWindow, vi->visual, AllocNone);
107+
108+
swa.colormap = cmap;
109+
swa.event_mask = ExposureMask | KeyPressMask;
110+
111+
hWindow = XCreateWindow(
112+
hDisplay, // display
113+
hRootWindow, // parent
114+
0, 0, width, height, // rect
115+
1, // border width
116+
bits, // depth
117+
InputOutput, // class
118+
vi->visual, // visual
119+
CWColormap | CWEventMask, // value mask
120+
&swa);
121+
XMapWindow(hDisplay, hWindow);
122+
XStoreName(hDisplay, hWindow, title);
123+
124+
GC = glXCreateContext(hDisplay, vi, NULL, GL_TRUE);
125+
glXMakeCurrent(hDisplay, hWindow, GC);
126+
glEnable(GL_DEPTH_TEST);
127+
128+
// TODO: IMPLEMENT fullscreen
129+
130+
CenterWindow();
131+
132+
return true;
133+
}
134+
135+
void LinuxPlatform::GetDesktopSize(int *width, int *height)
136+
{
137+
*width = 800;
138+
*height = 600;
139+
// TODO: IMPLEMENT
140+
}
141+
142+
void LinuxPlatform::CenterWindow()
143+
{
144+
// TODO: IMPLEMENT
145+
}
146+
147+
void LinuxPlatform::KillPlatformWindow()
148+
{
149+
glXMakeCurrent(hDisplay, None, NULL);
150+
glXDestroyContext(hDisplay, GC);
151+
XDestroyWindow(hDisplay, hWindow);
152+
XCloseDisplay(hDisplay);
153+
}
154+
155+
Platform *Platform::instance = NULL;
156+
157+
bool Platform::keys[KEY_MAX];
158+
bool Platform::mouseButtons[3];
159+
Vector2 Platform::mousePosition;
160+
161+
Platform::Platform()
162+
{
163+
LinuxPlatform::instance = new LinuxPlatform();
164+
instance = this;
165+
LinuxPlatform::instance->platform = this;
166+
167+
for (int i = 0; i < KEY_MAX; i++)
168+
{
169+
keys[i] = false;
170+
localKeymap[i] = KEY_UNDEFINED;
171+
}
172+
}
173+
174+
void Platform::Init()
175+
{
176+
Init(800, 600, 24, false);
177+
}
178+
179+
void Platform::Init(int w, int h, int bits, bool fullscreen)
180+
{
181+
LinuxPlatform::instance->CreatePlatformWindow("Monocle Powered", w, h, bits, fullscreen);
182+
width = w;
183+
height = h;
184+
}
185+
186+
void Platform::Update()
187+
{
188+
XEvent event;
189+
190+
while (XPending(LinuxPlatform::instance->hDisplay)) {
191+
XNextEvent(LinuxPlatform::instance->hDisplay, &event);
192+
switch(event.type) {
193+
case Expose:
194+
glViewport(0, 0, width, height);
195+
ShowBuffer();
196+
break;
197+
case KeyPress:
198+
break;
199+
}
200+
}
201+
}
202+
203+
void Platform::SetMouseButton(int button, bool on)
204+
{
205+
mouseButtons[button] = on;
206+
}
207+
208+
long Platform::GetMilliseconds()
209+
{
210+
return (long)time(0);
211+
}
212+
213+
bool Platform::IsKeyPressed(KeyCode keyCode)
214+
{
215+
return instance->keys[(int)keyCode];
216+
}
217+
218+
void Platform::ShowBuffer()
219+
{
220+
glXSwapBuffers(LinuxPlatform::instance->hDisplay, LinuxPlatform::instance->hWindow);
221+
}
222+
223+
int Platform::GetWidth()
224+
{
225+
return instance->width;
226+
}
227+
228+
int Platform::GetHeight()
229+
{
230+
return instance->height;
231+
}
232+
233+
void Platform::WindowSizeChanged(int w, int h)
234+
{
235+
instance->width = w;
236+
instance->height = h;
237+
Graphics::Resize(w, h);
238+
}
239+
240+
void Platform::SetLocalKey(int key, bool on)
241+
{
242+
}
243+
}
244+
245+
#endif

Code/Linux/LinuxPlatform.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifdef MONOCLE_LINUX
2+
3+
#pragma once
4+
5+
#include "../Platform.h"
6+
7+
#define LINUX_LEAN_AND_MEAN
8+
9+
#include <X11/Xlib.h>
10+
#include<GL/glx.h>
11+
12+
namespace Monocle
13+
{
14+
class LinuxPlatform
15+
{
16+
public:
17+
18+
Display *hDisplay;
19+
int hScreen;
20+
Window hWindow;
21+
GLXContext GC;
22+
23+
bool active; // Window Active Flag Set To TRUE By Default
24+
bool fullscreen; // Fullscreen Flag Set To Fullscreen Mode By Default
25+
26+
static LinuxPlatform* instance;
27+
Platform *platform;
28+
29+
LinuxPlatform()
30+
: hDisplay(NULL),
31+
hScreen(NULL),
32+
hWindow(NULL),
33+
GC(NULL)
34+
{
35+
active = true;
36+
fullscreen = true;
37+
instance = this;
38+
}
39+
40+
bool CreatePlatformWindow(const char* title, int width, int height, int bits, bool fullscreenflag);
41+
void KillPlatformWindow();
42+
void CenterWindow();
43+
static void GetDesktopSize(int *width, int *height);
44+
};
45+
46+
}
47+
48+
#endif

0 commit comments

Comments
 (0)