Most SDL functions reimplemented.

master
Per Inge Mathisen 2011-12-13 17:26:01 +01:00
parent fa5e6c73d3
commit cc662f9ac9
10 changed files with 281 additions and 40 deletions

View File

@ -1,4 +1,4 @@
AM_CPPFLAGS = -DYY_NO_INPUT $(WZ_CPPFLAGS) $(QT4_CFLAGS)
AM_CPPFLAGS = -DYY_NO_INPUT $(SDL_CFLAGS) $(WZ_CPPFLAGS) $(QT4_CFLAGS)
AM_CFLAGS = $(WZ_CFLAGS)
AM_CXXFLAGS = $(WZ_CXXFLAGS) $(QT4_CFLAGS)
AM_LFLAGS = $(FLEX_FLAGS)

View File

@ -48,6 +48,8 @@ bool selfTest = false;
* Player globals
*/
static bool mousewarp = false;
uint32_t selectedPlayer = 0; /**< Current player */
uint32_t realSelectedPlayer = 0;
@ -143,6 +145,16 @@ void frameShutDown(void)
resShutDown();
}
void setMouseWarp(bool value)
{
mousewarp = value;
}
bool getMouseWarp()
{
return mousewarp;
}
PHYSFS_file* openLoadFile(const char* fileName, bool hard_fail)
{
PHYSFS_file* fileHandle = PHYSFS_openRead(fileName);

View File

@ -34,6 +34,7 @@
#include "lib/framework/utf.h"
#include "vector.h"
#ifdef BACKEND_QT
/** Defines for all the key codes used. */
enum KEY_CODE
{
@ -145,6 +146,135 @@ enum KEY_CODE
KEY_IGNORE = 5190
};
enum MOUSE_KEY_CODE
{
MOUSE_LMB = 1,
MOUSE_MMB,
MOUSE_RMB,
MOUSE_WUP,
MOUSE_WDN,
MOUSE_BAD
};
#else
#include <SDL.h>
enum KEY_CODE
{
KEY_ESC =SDLK_ESCAPE,
KEY_1 =SDLK_1,
KEY_2 =SDLK_2,
KEY_3 =SDLK_3,
KEY_4 =SDLK_4,
KEY_5 =SDLK_5,
KEY_6 =SDLK_6,
KEY_7 =SDLK_7,
KEY_8 =SDLK_8,
KEY_9 =SDLK_9,
KEY_0 =SDLK_0,
KEY_MINUS =SDLK_MINUS,
KEY_EQUALS =SDLK_EQUALS,
KEY_BACKSPACE =SDLK_BAC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F9 =SDLK_F9,
KEY_F10 =SDLK_F10,
KEY_NUMLOCK =SDLK_NUMLOCK,
KEY_SCROLLLOCK =SDLK_SCROLLOCK,
KEY_KP_7 =SDLK_KP7,
KEY_KP_8 =SDLK_KP8,
KEY_KP_9 =SDLK_KP9,
KEY_KP_MINUS =SDLK_KP_MINUS,
KEY_KP_4 =SDLK_KP4,
KEY_KP_5 =SDLK_KP5,
KEY_KP_6 =SDLK_KP6,
KEY_KP_PLUS =SDLK_KP_PLUS,
KEY_KP_1 =SDLK_KP1,
KEY_KP_2 =SDLK_KP2,
KEY_KP_3 =SDLK_KP3,
KEY_KP_0 =SDLK_KP0,
KEY_KP_FULLSTOP =SDLK_KP_PERIOD,
KEY_F11 =SDLK_F11,
KEY_F12 =SDLK_F12,
KEY_RCTRL =SDLK_RCTRL,
KEY_KP_BACKSLASH =SDLK_KP_DIVIDE,
KEY_RALT =SDLK_RALT,
KEY_HOME =SDLK_HOME,
KEY_UPARROW =SDLK_UP,
KEY_PAGEUP =SDLK_PAGEUP,
KEY_LEFTARROW =SDLK_LEFT,
KEY_RIGHTARROW =SDLK_RIGHT,
KEY_END =SDLK_END,
KEY_DOWNARROW =SDLK_DOWN,
KEY_PAGEDOWN =SDLK_PAGEDOWN,
KEY_INSERT =SDLK_INSERT,
KEY_DELETE =SDLK_DELETE,
KEY_KPENTER =SDLK_KP_ENTER,
KEY_IGNORE =5190
};
/** The largest possible scan code. */
#define KEY_MAXSCAN SDLK_LAST
enum MOUSE_KEY_CODE
{
MOUSE_LMB = SDL_BUTTON_LEFT,
MOUSE_MMB = SDL_BUTTON_MIDDLE,
MOUSE_RMB = SDL_BUTTON_RIGHT,
MOUSE_WUP = SDL_BUTTON_WHEELUP,
MOUSE_WDN = SDL_BUTTON_WHEELDOWN
};
#endif
/** Tell the input system that we have lost the focus. */
extern void inputLoseFocus(void);
@ -164,16 +294,6 @@ extern bool keyPressed(KEY_CODE code);
/** This returns true if the key went from being down to being up this frame. */
extern bool keyReleased(KEY_CODE code);
enum MOUSE_KEY_CODE
{
MOUSE_LMB = 1,
MOUSE_MMB,
MOUSE_RMB,
MOUSE_WUP,
MOUSE_WDN,
MOUSE_BAD
};
/** Return the current X position of the mouse. */
extern uint16_t mouseX(void) WZ_DECL_PURE;

View File

@ -25,13 +25,21 @@
#include <QtCore/QSize>
#ifdef BACKEND_QT
struct _wzThread;
struct _wzMutex;
struct _wzSemaphore;
typedef struct _wzThread WZ_THREAD;
typedef struct _wzMutex WZ_MUTEX;
typedef struct _wzSemaphore WZ_SEMAPHORE;
#else
struct SDL_Thread;
struct SDL_mutex;
struct SDL_semaphore;
typedef SDL_Thread WZ_THREAD;
typedef SDL_mutex WZ_MUTEX;
typedef SDL_semaphore WZ_SEMAPHORE;
#endif
void wzMain(int &argc, char **argv);
bool wzMain2();
@ -51,10 +59,8 @@ bool wzGetSwapInterval();
// Thread related
WZ_THREAD *wzThreadCreate(int (*threadFunc)(void *), void *data);
#define wzThreadJoinResult(x, y) do { *(y) = wzThreadJoin(x); } while (0)
int wzThreadJoin(WZ_THREAD *thread);
void wzThreadStart(WZ_THREAD *thread);
bool wzIsThreadDone(WZ_THREAD *thread);
void wzYieldCurrentThread(void);
WZ_MUTEX *wzMutexCreate(void);
void wzMutexDestroy(WZ_MUTEX *mutex);
@ -64,6 +70,5 @@ WZ_SEMAPHORE *wzSemaphoreCreate(int startValue);
void wzSemaphoreDestroy(WZ_SEMAPHORE *semaphore);
void wzSemaphoreWait(WZ_SEMAPHORE *semaphore);
void wzSemaphorePost(WZ_SEMAPHORE *semaphore);
int wzSemaphoreAvailable(WZ_SEMAPHORE *semaphore);
#endif

View File

@ -699,7 +699,7 @@ void NETaddRedirects(void)
debug(LOG_NET, "%s\n", __FUNCTION__);
if (!upnp_done)
{
wzThreadJoinResult(upnpdiscover, &upnp);
upnp = wzThreadJoin(upnpdiscover);
upnp_done = true;
}
if (upnp) {

View File

@ -48,8 +48,6 @@
#include "lib/gamelib/gtime.h"
#include <deque>
static bool mousewarp = false;
/* The possible states for keys */
typedef enum _key_state
{
@ -786,16 +784,6 @@ Vector2i mouseReleasePos(MOUSE_KEY_CODE code)
return aMouseState[code].releasePos;
}
void setMouseWarp(bool value)
{
mousewarp = value;
}
bool getMouseWarp()
{
return mousewarp;
}
void setMousePos(uint16_t x, uint16_t y)
{
if (mousewarp)
@ -1025,11 +1013,6 @@ void wzThreadStart(WZ_THREAD *thread)
thread->start();
}
bool wzIsThreadDone(WZ_THREAD *thread)
{
return thread->isFinished();
}
void wzYieldCurrentThread()
{
#if QT_VERSION >= 0x040500
@ -1077,11 +1060,6 @@ void wzSemaphorePost(WZ_SEMAPHORE *semaphore)
semaphore->release();
}
int wzSemaphoreAvailable(WZ_SEMAPHORE *semaphore)
{
return semaphore->available();
}
/**************************/
/*** Font support ***/
/**************************/

View File

@ -1,4 +1,4 @@
AM_CPPFLAGS = -DYY_NO_INPUT $(WZ_CPPFLAGS)
AM_CPPFLAGS = -DYY_NO_INPUT $(SDL_CFLAGS) $(WZ_CPPFLAGS)
AM_CFLAGS = $(WZ_CFLAGS)
AM_CXXFLAGS = $(WZ_CXXFLAGS)
@ -8,4 +8,5 @@ noinst_HEADERS = \
libsdl_a_SOURCES = \
main_sdl.cpp \
input.cpp \
scrap.cpp

View File

@ -1,7 +1,128 @@
#include <QtCore/QCoreApplication>
#include "lib/framework/wzapp.h"
#include <SDL.h>
#include <SDL_thread.h>
#include <SDL_timer.h>
extern void mainLoop();
unsigned int screenWidth = 0;
unsigned int screenHeight = 0;
/**************************/
/*** Misc support ***/
/**************************/
void wzSetCursor(CURSOR index)
{
// TBD
}
void wzShowMouse(bool visible)
{
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
}
int wzGetTicks()
{
return SDL_GetTicks();
}
void wzFatalDialog(char const*)
{
// no-op
}
void wzScreenFlip()
{
SDL_GL_SwapBuffers();
}
void wzQuit()
{
// no-op
}
void wzGrabMouse()
{
SDL_WM_GrabInput(SDL_GRAB_ON);
}
void wzReleaseMouse()
{
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
/**************************/
/*** Thread support ***/
/**************************/
WZ_THREAD *wzThreadCreate(int (*threadFunc)(void *), void *data)
{
return SDL_CreateThread(threadFunc, data);
}
int wzThreadJoin(WZ_THREAD *thread)
{
int result;
SDL_WaitThread(thread, &result);
return result;
}
void wzThreadStart(WZ_THREAD *thread)
{
(void)thread; // no-op
}
void wzYieldCurrentThread()
{
SDL_Delay(40);
}
WZ_MUTEX *wzMutexCreate()
{
return SDL_CreateMutex();
}
void wzMutexDestroy(WZ_MUTEX *mutex)
{
SDL_DestroyMutex(mutex);
}
void wzMutexLock(WZ_MUTEX *mutex)
{
SDL_LockMutex(mutex);
}
void wzMutexUnlock(WZ_MUTEX *mutex)
{
SDL_UnlockMutex(mutex);
}
WZ_SEMAPHORE *wzSemaphoreCreate(int startValue)
{
return SDL_CreateSemaphore(startValue);
}
void wzSemaphoreDestroy(WZ_SEMAPHORE *semaphore)
{
SDL_DestroySemaphore(semaphore);
}
void wzSemaphoreWait(WZ_SEMAPHORE *semaphore)
{
SDL_SemWait(semaphore);
}
void wzSemaphorePost(WZ_SEMAPHORE *semaphore)
{
SDL_SemPost(semaphore);
}
/**************************/
/*** Main support ***/
/**************************/
void wzMain(int &argc, char **argv)
{
QCoreApplication app(argc, argv); // For Qt-script.

View File

@ -1,4 +1,4 @@
AM_CPPFLAGS = $(WZ_CPPFLAGS) $(QT4_CFLAGS)
AM_CPPFLAGS = $(SDL_CFLAGS) $(WZ_CPPFLAGS) $(QT4_CFLAGS)
AM_CFLAGS = $(WZ_CFLAGS)
AM_CXXFLAGS = $(WZ_CXXFLAGS) $(QT4_CFLAGS)

View File

@ -281,6 +281,10 @@ if BACKEND_QT
warzone2100_LIBS += $(top_builddir)/lib/qtgame/libqtgame.a
endif
if BACKEND_SDL
warzone2100_LIBS += $(top_builddir)/lib/sdl/libsdl.a
endif
warzone2100_LDADD = $(warzone2100_LIBS) $(LTLIBINTL) $(SDL_LIBS) $(PHYSFS_LIBS) $(PNG_LIBS) $(OGGVORBIS_LIBS) \
$(THEORA_LIBS) $(OPENAL_LIBS) $(OPENGLC_LIBS) $(OPENGL_LIBS) $(QT4_LIBS) $(QJSON_LIBS) $(GLEW_LIBS) \
$(X_LIBS) $(X_EXTRA_LIBS) $(LDFLAGS)