Skip to content

Commit

Permalink
Brought Unix port up-to-date with latest features.
Browse files Browse the repository at this point in the history
  • Loading branch information
agustincordes committed Aug 10, 2012
1 parent d9689b4 commit e6af1fd
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 18 deletions.
110 changes: 94 additions & 16 deletions Dagon/DGSystemUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ DGSystem::~DGSystem() {
// Implementation
////////////////////////////////////////////////////////////

void DGSystem::browse(const char* url) {
char aux[DGMaxFileLength];

if (config->fullScreen) {
this->toggleFullScreen();
}

strcpy(aux, "xdg-open ");
strcat(aux, url);
system(aux);
}

void DGSystem::createThreads() {
pthread_create(&tAudioThread, NULL, &_audioThread, NULL);
pthread_create(&tTimerThread, NULL, &_timerThread, NULL);
Expand Down Expand Up @@ -158,6 +170,8 @@ void DGSystem::init() {
// Now we're ready to init the controller instance
control = &DGControl::getInstance();
control->init();
control->reshape(config->displayWidth, config->displayHeight);
control->update();
_isInitialized = true;

log->trace(DGModSystem, "%s", DGMsg040001);
Expand All @@ -182,6 +196,9 @@ void DGSystem::resumeThread(int threadID){
}

void DGSystem::run() {
char buffer[80];
static bool isDragging = false;
static bool isModified = false;
XEvent event;
KeySym key;

Expand All @@ -208,35 +225,71 @@ void DGSystem::run() {
GLWin.width = event.xconfigure.width;
GLWin.height = event.xconfigure.height;
pthread_mutex_lock(&_systemMutex);
config->displayWidth = GLWin.width;
config->displayHeight = GLWin.height;
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
control->reshape(GLWin.width, GLWin.height);
glXMakeCurrent(GLWin.dpy, None, NULL);
pthread_mutex_unlock(&_systemMutex);
}
break;
case MotionNotify:
pthread_mutex_lock(&_systemMutex);
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventMove);
if (isDragging)
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventDrag);
else
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventMove);
glXMakeCurrent(GLWin.dpy, None, NULL);
pthread_mutex_unlock(&_systemMutex);
break;
case ButtonPress:
pthread_mutex_lock(&_systemMutex);
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
if (event.xbutton.button == 1)
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventDown);
else if (event.xbutton.button == 3)
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventRightDown);
glXMakeCurrent(GLWin.dpy, None, NULL);
pthread_mutex_unlock(&_systemMutex);
isDragging = true;
break;
case ButtonRelease:
pthread_mutex_lock(&_systemMutex);
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventUp);
if (event.xbutton.button == 1)
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventUp);
else if (event.xbutton.button == 3)
control->processMouse(event.xbutton.x, event.xbutton.y, DGMouseEventRightUp);
glXMakeCurrent(GLWin.dpy, None, NULL);
pthread_mutex_unlock(&_systemMutex);
isDragging = false;
break;
case KeyPress:
key = XLookupKeysym(&event.xkey, 0);
case KeyPress:
pthread_mutex_lock(&_systemMutex);
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
control->processKey(key, false);
if (XLookupString(&event.xkey, buffer, 80, &key, 0)) {
if (isModified) {
control->processKey(key, DGKeyEventModified);
isModified = false;
}
else
control->processKey(key, DGKeyEventDown);
}
else {
if ((key == XK_Control_L) || (key == XK_Control_R))
isModified = true;
}
glXMakeCurrent(GLWin.dpy, None, NULL);
pthread_mutex_unlock(&_systemMutex);
break;

case KeyRelease:
key = XLookupKeysym(&event.xkey, 0);
pthread_mutex_lock(&_systemMutex);
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
control->processKey(key, DGKeyEventUp);
glXMakeCurrent(GLWin.dpy, None, NULL);
pthread_mutex_unlock(&_systemMutex);
break;
case ClientMessage:
// TODO: Simulate ESC key
this->terminate();
Expand Down Expand Up @@ -274,10 +327,8 @@ void DGSystem::terminate() {
_isRunning = false;
}

void DGSystem::toggleFullScreen() {
killGLWindow();
GLWin.fs = config->fullScreen;
createGLWindow("Dagon", config->displayWidth, config->displayHeight, config->displayDepth, GLWin.fs);
void DGSystem::toggleFullScreen() {
log->warning(DGModSystem, "Toggling fullscreen currently disabled in Linux");
}

void DGSystem::update() {
Expand Down Expand Up @@ -329,6 +380,7 @@ bool createGLWindow(char* title, int width, int height, int bits,
bestMode = i;
}
}

// get an appropriate visual
vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDbl);
if (vi == NULL)
Expand All @@ -352,11 +404,22 @@ bool createGLWindow(char* title, int width, int height, int bits,

if (GLWin.fs)
{
XF86VidModeSwitchToMode(GLWin.dpy, GLWin.screen, modes[bestMode]);
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
dpyWidth = modes[bestMode]->hdisplay;
dpyHeight = modes[bestMode]->vdisplay;
printf("Resolution %dx%d\n", dpyWidth, dpyHeight);
if (DGConfig::getInstance().forcedFullScreen) {
XF86VidModeSwitchToMode(GLWin.dpy, GLWin.screen, modes[bestMode]);
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
dpyWidth = modes[bestMode]->hdisplay;
dpyHeight = modes[bestMode]->vdisplay;
printf("Resolution %dx%d\n", dpyWidth, dpyHeight);
}
else {
XF86VidModeSwitchToMode(GLWin.dpy, GLWin.screen, &GLWin.deskMode);
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
dpyWidth = (&GLWin.deskMode)->hdisplay;
dpyHeight = (&GLWin.deskMode)->vdisplay;
DGConfig::getInstance().displayWidth = dpyWidth;
DGConfig::getInstance().displayHeight = dpyHeight;
printf("Resolution %dx%d\n", dpyWidth, dpyHeight);
}
XFree(modes);

// create a fullscreen window
Expand Down Expand Up @@ -391,13 +454,28 @@ bool createGLWindow(char* title, int width, int height, int bits,
}
// connect the glx-context to the window
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);

XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y,
&GLWin.width, &GLWin.height, &borderDummy, &GLWin.depth);
printf("Depth %d\n", GLWin.depth);
if (glXIsDirect(GLWin.dpy, GLWin.ctx))
printf("Congrats, you have Direct Rendering!\n");
else
printf("Sorry, no Direct Rendering possible!\n");

// Hide the cursor

Cursor invisibleCursor;
Pixmap bitmapNoData;
XColor black;
static char noData[] = { 0,0,0,0,0,0,0,0 };
black.red = black.green = black.blue = 0;

bitmapNoData = XCreateBitmapFromData(GLWin.dpy, GLWin.win, noData, 8, 8);
invisibleCursor = XCreatePixmapCursor(GLWin.dpy, bitmapNoData, bitmapNoData,
&black, &black, 0, 0);
XDefineCursor(GLWin.dpy,GLWin.win, invisibleCursor);
XFreeCursor(GLWin.dpy, invisibleCursor);

return true;
}
Expand Down
6 changes: 4 additions & 2 deletions Linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ SRC_DIR:= ../Dagon
CC:= gcc
INCLUDE:= -I $(SRC_DIR) -I $(OTHERS_DIR) -I /usr/include/freetype2 -I /usr/include/lua5.1
LIBS:= -Wl -lXxf86vm -lGL -lGLU -lGLEW -lopenal -llua5.1 -lfreetype -logg -lvorbis -lvorbisfile -ltheora -lm
CFLAGS:= -O2 -Wall $(INCLUDE)
CFLAGS:= -O2 -Wall -static $(INCLUDE)

MODULES:= DGAudio DGAudioManager DGButton DGCameraManager \
DGConfig DGConsole DGControl DGCursorManager DGEffectsManager \
DGConfig DGConsole DGControl DGCursorManager DGDustData DGEffectsManager \
DGFeedManager DGFont DGFontData DGFontManager DGImage \
DGInterface DGLog DGNode DGObject DGOverlay DGRenderManager \
DGRoom DGScene DGScript DGShaderData DGSplashData DGSpot DGState \
Expand Down Expand Up @@ -54,6 +54,8 @@ $(OBJS_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CC) $(CFLAGS) -c $< -o $@

#--- Special cases
$(OBJS_DIR)/DGDustData.o: $(SRC_DIR)/DGDustData.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJS_DIR)/DGFontData.o: $(SRC_DIR)/DGFontData.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJS_DIR)/DGShaderData.o: $(SRC_DIR)/DGShaderData.c
Expand Down

0 comments on commit e6af1fd

Please sign in to comment.