Skip to content

Commit

Permalink
windows build working
Browse files Browse the repository at this point in the history
  • Loading branch information
U-inolen-PC\inolen authored and U-inolen-PC\inolen committed Feb 8, 2012
1 parent 00d25dd commit 6e9f15f
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
*.sublime-*
*.o
*.so
build/
bootstrap/
ioquake3/*
!ioquake3/Makefile.local
4 changes: 2 additions & 2 deletions plugin/Factory.cc
Expand Up @@ -3,11 +3,11 @@
#include <boost/make_shared.hpp>

#if defined FB_WIN
#include "X11/Q3PluginWin.h"
#include "Win/Q3PluginWin.h"
#define Q3PLUGIN Q3PluginWin
#elif defined FB_MACOSX
#include "X11/Q3PluginMac.h"
#define Q3PLUGIN Q3pluginMac
#define Q3PLUGIN Q3PluginMac
#else
#include "X11/Q3PluginX11.h"
#define Q3PLUGIN Q3PluginX11
Expand Down
6 changes: 4 additions & 2 deletions plugin/GameProcess.cc
Expand Up @@ -24,10 +24,10 @@ bool GameProcess::Spawn(int width, int height, const std::string& connectTo) {
argv_[4] = strdup("-1");
argv_[5] = strdup("+r_customWidth");
argv_[6] = (char*)malloc(sizeof(char) * 8);
snprintf(argv_[6], 8, "%i", width);
sprintf(argv_[6], "%i", width);
argv_[7] = strdup("+r_customHeight");
argv_[8] = (char*)malloc(sizeof(char) * 8);
snprintf(argv_[8], 8, "%i", height);
sprintf(argv_[8], "%i", height);

if (!connectTo.empty()) {
argv_[9] = strdup("+connect");
Expand All @@ -36,6 +36,8 @@ bool GameProcess::Spawn(int width, int height, const std::string& connectTo) {

// Spawn the native process.
SpawnNativeProcess();

return true;
}

void GameProcess::Kill() {
Expand Down
6 changes: 3 additions & 3 deletions plugin/Q3Plugin.cc
@@ -1,15 +1,15 @@
#include "Q3Plugin.h"
#include <boost/filesystem/operations.hpp>
#include <unistd.h>
//#include <unistd.h>
#include "FactoryBase.h"
#include "Q3PluginApi.h"

// TODO Merge this with Q3PluginFactory.
#if defined FB_WIN
#include "X11/GameProcessWin.h"
#include "Win/GameProcessWin.h"
#define Q3PROCESS GameProcessWin
#elif defined FB_MACOSX
#include "X11/GameProcessMac.h"
#include "Mac/GameProcessMac.h"
#define Q3PROCESS GameProcessMac
#else
#include "X11/GameProcessX11.h"
Expand Down
2 changes: 1 addition & 1 deletion plugin/ServerCommands.cc
Expand Up @@ -61,7 +61,7 @@ void ServerCommandClient::WaitForResponse(std::vector<unsigned char>& response,
}

template <typename MutableBufferSequence>
size_t ServerCommandClient::ReadWithTimeout(const MutableBufferSequence& buffer, size_t& count, int seconds) {
void ServerCommandClient::ReadWithTimeout(const MutableBufferSequence& buffer, size_t& count, int seconds) {
boost::optional<boost::system::error_code> timer_result;
boost::optional<boost::system::error_code> read_result;

Expand Down
2 changes: 1 addition & 1 deletion plugin/ServerCommands.h
Expand Up @@ -15,7 +15,7 @@ class ServerCommandClient {

private:
template <typename MutableBufferSequence>
size_t ReadWithTimeout(const MutableBufferSequence& buffer, size_t& count, int seconds);
void ReadWithTimeout(const MutableBufferSequence& buffer, size_t& count, int seconds);

boost::asio::io_service io_service_;
boost::asio::ip::udp::endpoint receiver_endpoint_;
Expand Down
58 changes: 58 additions & 0 deletions plugin/Win/GameProcessWin.cc
@@ -0,0 +1,58 @@
#include "GameProcessWin.h"
#include <boost/filesystem/operations.hpp>
//#include <glib.h>
//#include <sys/wait.h>
#include "PluginWindow.h"
#include "PluginWindowWin.h"

namespace fs = boost::filesystem;

GameProcessWin::GameProcessWin(FB::PluginWindow *window, const std::string& path) :
/*gamepid_(0),*/
GameProcess(window, path) {
}

GameProcessWin::~GameProcessWin() {
Kill();
}

bool GameProcessWin::SpawnNativeProcess() {
/*FB::PluginWindowWin *window = dynamic_cast<FB::PluginWindowWin*>(window_);
// SDL hijacking! Setting the SDL_WINDOWID environment variable will cause any
// subsequent calls to SDL_SetVideoMade (like the one made in the ioquake3
// initialization) use the specified window id for rendering, instead of
// creating a new one.
const int xid = window->getWindow();
std::ostringstream sxid;
sxid << xid;
setenv("SDL_WINDOWID", sxid.str().c_str(), TRUE);
// Install the shim. This shim gets loaded before any other shared assemblies,
// allowing us to override functions in subsequently loaded assemblies. We use
// this to do things such as intercepting the SDL event polling and
// injecting our own translated events from GTK.
fs::path p(path_);
std::ostringstream shimPath;
shimPath << p.parent_path() << "/libq3pluginshim.so";
setenv("LD_PRELOAD", shimPath.str().c_str(), TRUE);
// Launch game.
g_spawn_async(NULL, (gchar**)argv_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &gamepid_, NULL);*/
return true;
}

void GameProcessWin::KillNativeProcess() {
/*if (gamepid_ != 0) {
// Request the child process terminate.
kill(gamepid_, SIGTERM);
// Wait for it to.
waitpid(gamepid_, NULL, 0);
// Close process resource.
g_spawn_close_pid(gamepid_);
gamepid_ = 0;
}*/
}
19 changes: 19 additions & 0 deletions plugin/Win/GameProcessWin.h
@@ -0,0 +1,19 @@
#ifndef GAMEPROCESSWIN_H
#define GAMEPROCESSWIN_H

#include "../GameProcess.h"

class GameProcessWin : public GameProcess {
public:
GameProcessWin(FB::PluginWindow *window, const std::string& path);
virtual ~GameProcessWin();

protected:
virtual bool SpawnNativeProcess();
virtual void KillNativeProcess();

private:
//pid_t gamepid_;
};

#endif
138 changes: 138 additions & 0 deletions plugin/Win/Q3PluginWin.cc
@@ -0,0 +1,138 @@
#include "Q3PluginWin.h"
#include <SDL.h>
#include "PluginEvents/KeyCodes.h"
#include "PluginWindowWin.h"
#include "../Q3PluginApi.h"

/*static int fb_to_sdl(FB::FBKeyCode key) {
switch (key) {
case FB::FBKEY_PAGEUP:
return SDLK_PAGEUP;
case FB::FBKEY_PAGEDOWN:
return SDLK_PAGEDOWN;
case FB::FBKEY_RETURN:
return SDLK_RETURN;
}
return -1;
}*/

Q3PluginWin::Q3PluginWin() {
}

Q3PluginWin::~Q3PluginWin() {
}

void Q3PluginWin::ProcessMessage(message_t& msg) {
/*Q3Plugin::ProcessMessage(msg);
if (msg.type == MOUSELOCK) {
mouseLocked_ = msg.mouselock.lock;
}*/
}

bool Q3PluginWin::onKeyDown(FB::KeyDownEvent *evt, FB::PluginWindow *window) {
/*int key = evt->m_os_key_code >= 0 && evt->m_os_key_code <= 255 ? evt->m_os_key_code : fb_to_sdl(evt->m_key_code);
if (key != -1) {
message_t msg;
msg.type = SDLEVENT;
msg.sdlevent.event.type = SDL_KEYDOWN;
msg.sdlevent.event.key.keysym.sym = (SDLKey)key;
msg.sdlevent.event.key.keysym.unicode = key;
SendMessage(msg);
}
return true;*/
return false;
}

bool Q3PluginWin::onKeyUp(FB::KeyUpEvent *evt, FB::PluginWindow *window) {
/*int key = evt->m_os_key_code >= 0 && evt->m_os_key_code <= 255 ? evt->m_os_key_code : fb_to_sdl(evt->m_key_code);
if (key != -1) {
message_t msg;
msg.type = SDLEVENT;
msg.sdlevent.event.type = SDL_KEYUP;
msg.sdlevent.event.key.keysym.sym = (SDLKey)key;
msg.sdlevent.event.key.keysym.unicode = key;
SendMessage(msg);
}
return true;*/
return false;
}

bool Q3PluginWin::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *window) {
/*message_t msg;
msg.type = SDLEVENT;
msg.sdlevent.event.type = SDL_MOUSEBUTTONDOWN;
switch (evt->m_Btn) {
case 0:
msg.sdlevent.event.button.button = 1;
break;
case 1:
msg.sdlevent.event.button.button = 2;
break;
case 2:
msg.sdlevent.event.button.button = 3;
break;
}
SendMessage(msg);
return true;*/
return false;
}

bool Q3PluginWin::onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *window) {
/*message_t msg;
msg.type = SDLEVENT;
msg.sdlevent.event.type = SDL_MOUSEBUTTONUP;
switch (evt->m_Btn) {
case 0:
msg.sdlevent.event.button.button = 1;
break;
case 1:
msg.sdlevent.event.button.button = 2;
break;
case 2:
msg.sdlevent.event.button.button = 3;
break;
}
SendMessage(msg);
return true;*/
return false;
}

bool Q3PluginWin::onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *window) {
/*if (mouseLocked_) {
// Forward the event.
message_t msg;
msg.type = SDLEVENT;
msg.sdlevent.event.type = SDL_MOUSEMOTION;
msg.sdlevent.event.motion.xrel = evt->m_x - window->getWindowWidth()/2;
msg.sdlevent.event.motion.yrel = evt->m_y - window->getWindowHeight()/2;
SendMessage(msg);
// Center the mouse.
FB::PluginWindowX11 *window = dynamic_cast<FB::PluginWindowX11*>(GetWindow());
GtkWidget *widget = window->getWidget();
Display *xdsp = GDK_WINDOW_XDISPLAY(widget->window);
Window xwnd = GDK_WINDOW_XWINDOW(widget->window);
XWarpPointer(xdsp, None, xwnd, 0,0,0,0, window->getWindowWidth()/2, window->getWindowHeight()/2);
}
return true;*/
return false;
}
24 changes: 24 additions & 0 deletions plugin/Win/Q3PluginWin.h
@@ -0,0 +1,24 @@
#ifndef Q3PLUGINWIN_H
#define Q3PLUGINWIN_H

#include "../Q3Plugin.h"

class Q3PluginWin : public Q3Plugin {
public:
Q3PluginWin();
virtual ~Q3PluginWin();

protected:
virtual void ProcessMessage(message_t& msg);

virtual bool onKeyDown(FB::KeyDownEvent *evt, FB::PluginWindow *window);
virtual bool onKeyUp(FB::KeyUpEvent *evt, FB::PluginWindow *window);
virtual bool onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *window);
virtual bool onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *window);
virtual bool onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *window);

private:
bool mouseLocked_;
};

#endif
2 changes: 1 addition & 1 deletion plugin/Win/projectDef.cmake
Expand Up @@ -8,7 +8,7 @@

# remember that the current source dir is the project root; this file is in Win/
file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Win/[^.]*.cpp
Win/[^.]*.cc
Win/[^.]*.h
Win/[^.]*.cmake
)
Expand Down

0 comments on commit 6e9f15f

Please sign in to comment.