cmake_minimum_required(VERSION 3.5)
+INCLUDE(FindPkgConfig)
+
set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source")
set(DEPDIR "${CMAKE_CURRENT_SOURCE_DIR}/Dependencies")
if(APPLE)
# Save our sanity; Set all available libraries to internal by default
- set(LUGARU_FORCE_INTERNAL_SDL True)
set(LUGARU_FORCE_INTERNAL_GLU True)
set(LUGARU_FORCE_INTERNAL_JPEG True)
set(LUGARU_FORCE_INTERNAL_PNG True)
endif (NOT LUGARU_HAS_INTERNAL_OPENAL)
endif (NOT OPENAL_FOUND OR LUGARU_FORCE_INTERNAL_OPENAL)
-option (LUGARU_FORCE_INTERNAL_SDL "Force internal libSDL, even if there's a system version" False)
-if (NOT LUGARU_FORCE_INTERNAL_SDL)
- find_package(SDL)
-else(NOT LUGARU_FORCE_INTERNAL_SDL)
- set(SDL_FOUND False)
-endif (NOT LUGARU_FORCE_INTERNAL_SDL)
-
-if (NOT SDL_FOUND)
- message(STATUS "Using internal copy of SDL")
- set(LUGARU_MISSING_DEPS "${LUGARU_MISSING_DEPS} SDL")
- set(SDLDIR "${DEPDIR}/SDL12")
- set(SDL_INCLUDE_DIR "${SDLDIR}/include")
- set(SDL_LIBRARY "")
- if (APPLE)
- set(LUGARU_HAS_INTERNAL_SDL True)
- set(SDL_LIBRARY
- ${SDLDIR}/lib/macosx/libSDL-1.2.0.dylib
- ${SDLDIR}/lib/macosx/libSDLmain-osx.a
- )
- endif (APPLE)
-
- if (WIN32)
- set(LUGARU_HAS_INTERNAL_SDL True)
- if (MSVC)
- set(SDL_LIBRARY
- ${SDLDIR}/lib/win32/msvc2008/SDLmain.lib
- ${SDLDIR}/lib/win32/msvc2008/SDL.lib
- )
- endif (MSVC)
- if (MINGW)
- set(SDL_LIBRARY
- "mingw32"
- ${SDLDIR}/lib/win32/mingw/libSDLmain.a
- ${SDLDIR}/lib/win32/mingw/libSDL.dll.a
- "-mwindows"
- )
- endif (MINGW)
- endif (WIN32)
-
- if (NOT LUGARU_HAS_INTERNAL_SDL)
- message(ERROR "We don't have a prebuilt SDL for this platform.")
- endif (NOT LUGARU_HAS_INTERNAL_SDL)
-endif (NOT SDL_FOUND)
+PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
option (LUGARU_FORCE_INTERNAL_PNG "Force internal libPNG, even if there's a system version" False)
if (NOT LUGARU_FORCE_INTERNAL_PNG)
${ZLIB_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLU_INCLUDE_DIR}
- ${SDL_INCLUDE_DIR}
+ ${SDL2_INCLUDE_DIRS}
${VORBISFILE_INCLUDE_DIR}
${OGG_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/Source
)
-set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL_LIBRARY} ${OPENGL_glu_LIBRARY} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
+set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_glu_LIBRARY} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
if(WIN32)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
if(MSVC)
- install(FILES ${SDLDIR}/lib/win32/msvc2008/SDL.dll DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${OPENALDIR}/lib/win32/msvc2008/OpenAL32.dll DESTINATION ${CMAKE_INSTALL_PREFIX})
endif(MSVC)
if(MINGW)
- install(FILES ${SDLDIR}/lib/win32/mingw/SDL.dll DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${OPENALDIR}/lib/win32/mingw/OpenAL32.dll DESTINATION ${CMAKE_INSTALL_PREFIX})
endif(MINGW)
else(WIN32)
install(FILES ${SRCDIR}/mac-res/Info.plist DESTINATION ${APPS_ROOT}/Contents)
endif(APPLE)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
- if(APPLE AND LUGARU_HAS_INTERNAL_SDL)
- install(FILES ${SDLDIR}/lib/macosx/libSDL-1.2.0.dylib DESTINATION ${CMAKE_INSTALL_PREFIX})
- endif(APPLE AND LUGARU_HAS_INTERNAL_SDL)
endif(WIN32)
if(NOT APPLE)
int numchallengelevels = 0;
bool console = false;
-char consoletext[15][256] = {};
-int consolechars[15] = {};
+std::string consoletext[15] = {};
bool chatting = 0;
-char displaytext[15][256] = {};
-int displaychars[15] = {};
+std::string displaytext[15] = {};
float displaytime[15] = {};
float displayblinkdelay = 0;
bool displayblink = 0;
emit_sound_at(sound);
}
-void Game::inputText(char* str, int* charselected, int* nb_chars)
+void Game::inputText(string& str, int* charselected)
{
SDL_Event evenement;
if (!waiting) {
+ SDL_StartTextInput();
waiting = true;
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
- SDL_EnableUNICODE(true);
}
while (SDL_PollEvent(&evenement)) {
-
switch (evenement.type) {
+ case SDL_TEXTEDITING:
+ /* FIXME - We should handle this for complete input method support */
+ break;
+ case SDL_TEXTINPUT:
+ str.insert(*charselected, evenement.text.text);
+ (*charselected) += strlen(evenement.text.text);
+ break;
case SDL_KEYDOWN:
if (evenement.key.keysym.sym == SDLK_ESCAPE) {
- for (int i = 0; i < 255; i++)
- str[i] = 0;
- *nb_chars = 0;
+ str.clear();
*charselected = 0;
waiting = false;
} else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
- if ((*charselected) != 0) {
- for (int i = (*charselected) - 1; i < 255; i++)
- str[i] = str[i + 1];
- str[255] = 0;
+ if ((*charselected) > 0) {
(*charselected)--;
- (*nb_chars)--;
+ str.erase(*charselected, 1);
}
} else if (evenement.key.keysym.sym == SDLK_DELETE) {
- if ((*charselected) < (*nb_chars)) {
- for (int i = (*charselected); i < 255; i++)
- str[i] = str[i + 1];
- str[255] = 0;
- (*nb_chars)--;
+ if ((*charselected) < str.size()) {
+ str.erase(*charselected, 1);
}
} else if (evenement.key.keysym.sym == SDLK_HOME) {
(*charselected) = 0;
} else if (evenement.key.keysym.sym == SDLK_END) {
- (*charselected) = (*nb_chars);
+ (*charselected) = str.size();
} else if (evenement.key.keysym.sym == SDLK_LEFT) {
if ((*charselected) != 0)
(*charselected)--;
} else if (evenement.key.keysym.sym == SDLK_RIGHT) {
- if ((*charselected) < (*nb_chars))
+ if ((*charselected) < str.size())
(*charselected)++;
} else if (evenement.key.keysym.sym == SDLK_RETURN) {
waiting = false;
- } else if (evenement.key.keysym.unicode >= 32 && evenement.key.keysym.unicode < 127 && (*nb_chars) < 60) {
- for (int i = 255; i >= (*charselected) + 1; i--)
- str[i] = str[i - 1];
- str[*charselected] = evenement.key.keysym.unicode;
- (*charselected)++;
- (*nb_chars)++;
}
break;
}
}
if (!waiting) {
- SDL_EnableKeyRepeat(0, 0); // disable key repeat
- SDL_EnableUNICODE(false);
+ SDL_StopTextInput();
}
}
int setKeySelected_thread(void* data)
{
using namespace Game;
- int keycode = -1;
+ int scancode = -1;
SDL_Event evenement;
- while (keycode == -1) {
+ while (scancode == -1) {
SDL_WaitEvent(&evenement);
switch (evenement.type) {
case SDL_KEYDOWN:
- keycode = evenement.key.keysym.sym;
+ scancode = evenement.key.keysym.scancode;
break;
case SDL_MOUSEBUTTONDOWN:
- keycode = SDLK_LAST + evenement.button.button;
+ scancode = SDL_NUM_SCANCODES + evenement.button.button;
break;
default:
break;
}
}
- if (keycode != SDLK_ESCAPE) {
+ if (scancode != SDL_SCANCODE_ESCAPE) {
fireSound();
switch (keyselect) {
case 0:
- forwardkey = keycode;
+ forwardkey = scancode;
break;
case 1:
- backkey = keycode;
+ backkey = scancode;
break;
case 2:
- leftkey = keycode;
+ leftkey = scancode;
break;
case 3:
- rightkey = keycode;
+ rightkey = scancode;
break;
case 4:
- crouchkey = keycode;
+ crouchkey = scancode;
break;
case 5:
- jumpkey = keycode;
+ jumpkey = scancode;
break;
case 6:
- drawkey = keycode;
+ drawkey = scancode;
break;
case 7:
- throwkey = keycode;
+ throwkey = scancode;
break;
case 8:
- attackkey = keycode;
+ attackkey = scancode;
break;
case 9:
- consolekey = keycode;
+ consolekey = scancode;
break;
default:
break;
{
waiting = true;
printf("launch thread\n");
- SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL);
+ SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread, NULL, NULL);
if ( thread == NULL ) {
fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
waiting = false;
extern int numchallengelevels;
extern bool console;
-extern char consoletext[15][256];
-extern int consolechars[15];
+extern std::string consoletext[15];
extern bool chatting;
-extern char displaytext[15][256];
-extern int displaychars[15];
+extern std::string displaytext[15];
extern float displaytime[15];
extern float displayblinkdelay;
extern bool displayblink;
void fireSound(int sound = fireendsound);
void setKeySelected();
-void inputText(char* str, int* charselected, int* nb_chars);
+void inputText(std::string& str, int* charselected);
void flash();
}
static __forceinline void swap_gl_buffers(void)
{
- SDL_GL_SwapBuffers();
+ extern SDL_Window *sdlwindow;
+ SDL_GL_SwapWindow(sdlwindow);
+
+ // try to limit this to 60fps, even if vsync fails.
+ Uint32 now;
+ static Uint32 frameticks = 0;
+ const Uint32 endticks = (frameticks + 16);
+ while ((now = SDL_GetTicks()) < endticks) { /* spin. */ }
+ frameticks = now;
}
extern "C" {
}
for (i = 0; i < 15; i++)
if ((i != 0 || chatting) && displaytime[i] < 4)
- for (j = 0; j < displaychars[i]; j++) {
+ for (j = 0; j < displaytext[i].size(); j++) {
glColor4f(1, 1, 1, 4 - displaytime[i]);
- if (j < displaychars[i]) {
- sprintf (string, "%c", displaytext[i][j]);
- text->glPrint(30 + j * 10, 30 + i * 20 + (screenheight - 330), string, 0, 1, screenwidth, screenheight);
- }
+ sprintf (string, "%c", displaytext[i][j]);
+ text->glPrint(30 + j * 10, 30 + i * 20 + (screenheight - 330), string, 0, 1, screenwidth, screenheight);
}
}
text->glPrint(30 + (float)(consoleselected) * 10 - offset * 10, 30, string, 0, 1, 1024, 768);
}
for (i = 0; i < 15; i++)
- for (j = 0; j < consolechars[i]; j++) {
+ for (j = 0; j < consoletext[i].size(); j++) {
glColor4f(1, 1, 1, 1 - (float)(i) / 16);
- if (j < consolechars[i]) {
- sprintf (string, "%c", consoletext[i][j]);
- text->glPrint(30 + j * 10 - offset * 10, 30 + i * 20, string, 0, 1, 1024, 768);
- }
+ sprintf (string, "%c", consoletext[i][j]);
+ text->glPrint(30 + j * 10 - offset * 10, 30 + i * 20, string, 0, 1, 1024, 768);
}
}
}
{
float headprop, bodyprop, armprop, legprop;
if (debugmode) {
- if (Input::isKeyPressed(SDLK_h)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_H)) {
Person::players[0]->damagetolerance = 200000;
Person::players[0]->damage = 0;
Person::players[0]->burnt = 0;
Person::players[0]->superpermanentdamage = 0;
}
- if (Input::isKeyPressed(SDLK_j)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_J)) {
environment++;
if (environment > 2)
environment = 0;
Setenvironment(environment);
}
- if (Input::isKeyPressed(SDLK_c)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_C)) {
cameramode = 1 - cameramode;
}
- if (Input::isKeyPressed(SDLK_x) && !Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_X) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
if (Person::players[0]->num_weapons > 0) {
if (weapons[Person::players[0]->weaponids[0]].getType() == sword)
weapons[Person::players[0]->weaponids[0]].setType(staff);
}
}
- if (Input::isKeyPressed(SDLK_x) && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_X) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
int closest = findClosestPlayer();
if (closest >= 0) {
if (Person::players[closest]->num_weapons) {
}
}
- if (Input::isKeyDown(SDLK_u)) {
+ if (Input::isKeyDown(SDL_SCANCODE_U)) {
int closest = findClosestPlayer();
if (closest >= 0) {
Person::players[closest]->yaw += multiplier * 50;
}
- if (Input::isKeyPressed(SDLK_o) && !Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_O) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
int closest = findClosestPlayer();
- if (Input::isKeyDown(SDLK_LCTRL))
+ if (Input::isKeyDown(SDL_SCANCODE_LCTRL))
closest = 0;
if (closest >= 0) {
}
}
- if (Input::isKeyPressed(SDLK_o) && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_O) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
int closest = findClosestPlayer();
if (closest >= 0) {
if (Person::players[closest]->creature == wolftype) {
}
}
- if (Input::isKeyPressed(SDLK_b) && !Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_B) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
slomo = 1 - slomo;
slomodelay = 1000;
}
- if (((Input::isKeyPressed(SDLK_i) && !Input::isKeyDown(SDLK_LSHIFT)))) {
+ if (((Input::isKeyPressed(SDL_SCANCODE_I) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) {
int closest = -1;
float closestdist = std::numeric_limits<float>::max();
}
}
- if (((Input::isKeyPressed(SDLK_i) && Input::isKeyDown(SDLK_LSHIFT)))) {
+ if (((Input::isKeyPressed(SDL_SCANCODE_I) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) {
int closest = findClosestPlayer();
XYZ flatfacing2, flatvelocity2;
XYZ blah;
}
}
- if (Input::isKeyPressed(SDLK_f)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_F)) {
Person::players[0]->onfire = 1 - Person::players[0]->onfire;
if (Person::players[0]->onfire) {
Person::players[0]->CatchFire();
}
}
- if (Input::isKeyPressed(SDLK_n) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_N) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
//if(!Person::players[0]->skeleton.free)Person::players[0]->damage+=500;
Person::players[0]->RagDoll(0);
//Person::players[0]->spurt=1;
emit_sound_at(whooshsound, Person::players[0]->coords, 128.);
}
- if (Input::isKeyPressed(SDLK_n) && Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_N) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
for (int i = 0; i < objects.numobjects; i++) {
if (objects.type[i] == treeleavestype) {
objects.scale[i] *= .9;
}
}
- if (Input::isKeyPressed(SDLK_m) && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_M) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
editorenabled = 1 - editorenabled;
if (editorenabled) {
Person::players[0]->damagetolerance = 100000;
}
//skip level
- if (whichlevel != -2 && Input::isKeyPressed(SDLK_k) && Input::isKeyDown(SDLK_LSHIFT) && !editorenabled) {
+ if (whichlevel != -2 && Input::isKeyPressed(SDL_SCANCODE_K) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !editorenabled) {
targetlevel++;
if (targetlevel > numchallengelevels - 1)
targetlevel = 0;
}
if (editorenabled) {
- if (Input::isKeyPressed(SDLK_DELETE) && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
int closest = findClosestPlayer();
if (closest >= 0) {
Person::players.erase(Person::players.begin()+closest);
}
}
- if (Input::isKeyPressed(SDLK_DELETE) && Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
int closest = findClosestObject();
if (closest >= 0)
objects.position[closest].y -= 500;
}
- if (Input::isKeyPressed(SDLK_m) && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_M) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
//drawmode++;
//if(drawmode>2)drawmode=0;
if (objects.numobjects < max_objects - 1) {
}
}
- if (Input::isKeyPressed(SDLK_p) && Input::isKeyDown(SDLK_LSHIFT) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
Person::players.push_back(shared_ptr<Person>(new Person()));
Person::players.back()->scale = .2 * 5 * Person::players[0]->scale;
Person::players.back()->loaded = 1;
}
- if (Input::isKeyPressed(SDLK_p) && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
if (Person::players.back()->numwaypoints < 90) {
Person::players.back()->waypoints[Person::players.back()->numwaypoints] = Person::players[0]->coords;
Person::players.back()->waypointtype[Person::players.back()->numwaypoints] = editorpathtype;
}
}
- if (Input::isKeyPressed(SDLK_p) && Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
if (numpathpoints < 30) {
bool connected, alreadyconnected;
connected = 0;
}
}
- if (Input::isKeyPressed(SDLK_PERIOD)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_PERIOD)) {
pathpointselected++;
if (pathpointselected >= numpathpoints)
pathpointselected = -1;
}
- if (Input::isKeyPressed(SDLK_COMMA) && !Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
pathpointselected--;
if (pathpointselected <= -2)
pathpointselected = numpathpoints - 1;
}
- if (Input::isKeyPressed(SDLK_COMMA) && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
if (pathpointselected != -1) {
numpathpoints--;
pathpoint[pathpointselected] = pathpoint[numpathpoints];
}
}
- if (Input::isKeyPressed(SDLK_LEFT) && Input::isKeyDown(SDLK_LSHIFT) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editortype--;
if (editortype == treeleavestype || editortype == 10)
editortype--;
editortype = firetype;
}
- if (Input::isKeyPressed(SDLK_RIGHT) && Input::isKeyDown(SDLK_LSHIFT) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editortype++;
if (editortype == treeleavestype || editortype == 10)
editortype++;
editortype = 0;
}
- if (Input::isKeyDown(SDLK_LEFT) && !Input::isKeyDown(SDLK_LSHIFT) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyDown(SDL_SCANCODE_LEFT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editoryaw -= multiplier * 100;
if (editoryaw < -.01)
editoryaw = -.01;
}
- if (Input::isKeyDown(SDLK_RIGHT) && !Input::isKeyDown(SDLK_LSHIFT) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyDown(SDL_SCANCODE_RIGHT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editoryaw += multiplier * 100;
}
- if (Input::isKeyDown(SDLK_UP) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editorsize += multiplier;
}
- if (Input::isKeyDown(SDLK_DOWN) && !Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editorsize -= multiplier;
if (editorsize < .1)
editorsize = .1;
}
- if (Input::isKeyPressed(SDLK_LEFT) && Input::isKeyDown(SDLK_LSHIFT) && Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
mapradius -= multiplier * 10;
}
- if (Input::isKeyPressed(SDLK_RIGHT) && Input::isKeyDown(SDLK_LSHIFT) && Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
mapradius += multiplier * 10;
}
- if (Input::isKeyDown(SDLK_UP) && Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editorpitch += multiplier * 100;
}
- if (Input::isKeyDown(SDLK_DOWN) && Input::isKeyDown(SDLK_LCTRL)) {
+ if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
editorpitch -= multiplier * 100;
if (editorpitch < -.01)
editorpitch = -.01;
}
- if (Input::isKeyPressed(SDLK_DELETE) && objects.numobjects && Input::isKeyDown(SDLK_LSHIFT)) {
+ if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && objects.numobjects && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
int closest = findClosestObject();
if (closest >= 0)
objects.DeleteObject(closest);
mainmenu = 5;
else
mainmenu = 1;
- for (int j = 0; j < 255; j++) {
- displaytext[0][j] = 0;
- }
- displaychars[0] = 0;
+ displaytext[0].clear();
displayselected = 0;
entername = 0;
}
}
}
- if (Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)) {
+ if (Input::isKeyDown(SDL_SCANCODE_Q) && Input::isKeyDown(SDL_SCANCODE_LGUI)) {
tryquit = 1;
if (mainmenu == 3) {
SaveSettings();
OPENAL_SetFrequency(channels[stream_menutheme], 22050);
if (entername) {
- inputText(displaytext[0], &displayselected, &displaychars[0]);
+ inputText(displaytext[0], &displayselected);
if (!waiting) { // the input as finished
- if (displaychars[0]) { // with enter
+ if (!displaytext[0].empty()) { // with enter
accountactive = Account::add(string(displaytext[0]));
mainmenu = 8;
fireSound(firestartsound);
- for (int i = 0; i < 255; i++) {
- displaytext[0][i] = 0;
- }
- displaychars[0] = 0;
+ displaytext[0].clear();
displayselected = 0;
}
keyboardfrozen = false;
Input::Tick();
- if (Input::isKeyPressed(SDLK_F6)) {
- if (Input::isKeyDown(SDLK_LSHIFT))
+ if (Input::isKeyPressed(SDL_SCANCODE_F6)) {
+ if (Input::isKeyDown(SDL_SCANCODE_LSHIFT))
stereoreverse = true;
else
stereoreverse = false;
printf("Stereo unreversed\n");
}
- if (Input::isKeyDown(SDLK_F7)) {
- if (Input::isKeyDown(SDLK_LSHIFT))
+ if (Input::isKeyDown(SDL_SCANCODE_F7)) {
+ if (Input::isKeyDown(SDL_SCANCODE_LSHIFT))
stereoseparation -= 0.001;
else
stereoseparation -= 0.010;
printf("Stereo decreased increased to %f\n", stereoseparation);
}
- if (Input::isKeyDown(SDLK_F8)) {
- if (Input::isKeyDown(SDLK_LSHIFT))
+ if (Input::isKeyDown(SDL_SCANCODE_F8)) {
+ if (Input::isKeyDown(SDL_SCANCODE_LSHIFT))
stereoseparation += 0.001;
else
stereoseparation += 0.010;
}
- if (Input::isKeyPressed(SDLK_TAB) && tutoriallevel) {
+ if (Input::isKeyPressed(SDL_SCANCODE_TAB) && tutoriallevel) {
if (tutorialstage != 51)
tutorialstagetime = tutorialmaxtime;
emit_sound_np(consolefailsound, 128.);
LoadMenu();
}
//escape key pressed
- if (Input::isKeyPressed(SDLK_ESCAPE) &&
+ if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
(gameon || mainmenu == 0 || (mainmenu >= 3 && mainmenu != 8 && !(mainmenu == 7 && entername)))) {
selected = -1;
if (mainmenu == 0 && !winfreeze)
leveltime += multiplier;
//keys
- if (Input::isKeyPressed(SDLK_v) && debugmode) {
+ if (Input::isKeyPressed(SDL_SCANCODE_V) && debugmode) {
freeze = 1 - freeze;
if (freeze) {
OPENAL_SetFrequency(OPENAL_ALL, 0.001);
chatting = 1;
if (chatting) {
- inputText(displaytext[0], &displayselected, &displaychars[0]);
+ inputText(displaytext[0], &displayselected);
if (!waiting) {
- if (displaychars[0]) {
- for (int j = 0; j < 255; j++)
- displaytext[0][j] = 0;
- displaychars[0] = 0;
+ if (!displaytext[0].empty()) {
+ displaytext[0].clear();
displayselected = 0;
}
chatting = 0;
if (console)
freeze = 1;
- if (console && !Input::isKeyDown(SDLK_LMETA)) {
- inputText(consoletext[0], &consoleselected, &consolechars[0]);
+ if (console && !Input::isKeyDown(SDL_SCANCODE_LGUI)) {
+ inputText(consoletext[0], &consoleselected);
if (!waiting) {
- if (consolechars[0] > 0) {
- consoletext[0][consolechars[0]] = '\0';
+ if (!consoletext[0].empty()) {
cmd_dispatch(consoletext[0]);
for (int k = 14; k >= 1; k--) {
- for (int j = 0; j < 255; j++)
- consoletext[k][j] = consoletext[k - 1][j];
- consolechars[k] = consolechars[k - 1];
+ consoletext[k] = consoletext[k - 1];
}
- for (int j = 0; j < 255; j++)
- consoletext[0][j] = 0;
- consolechars[0] = 0;
+ consoletext[0].clear();
consoleselected = 0;
}
}
- if (Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)) {
+ if (Input::isKeyDown(SDL_SCANCODE_Q) && Input::isKeyDown(SDL_SCANCODE_LGUI)) {
tryquit = 1;
if (mainmenu == 3) {
SaveSettings();
else
oldwinfreeze++;
- if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDLK_SPACE)) && !campaign)
+ if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE)) && !campaign)
if (winfreeze)
winfreeze = 0;
- if ((Input::isKeyDown(SDLK_ESCAPE)) && !campaign && gameon) {
+ if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && !campaign && gameon) {
if (console) {
console = false;
freeze = 0;
viewer.y += multiplier * 4;
if (Input::isKeyDown(crouchkey))
viewer.y -= multiplier * 4;
- if ( Input::isKeyPressed(SDLK_1) ||
- Input::isKeyPressed(SDLK_2) ||
- Input::isKeyPressed(SDLK_3) ||
- Input::isKeyPressed(SDLK_4) ||
- Input::isKeyPressed(SDLK_5) ||
- Input::isKeyPressed(SDLK_6) ||
- Input::isKeyPressed(SDLK_7) ||
- Input::isKeyPressed(SDLK_8) ||
- Input::isKeyPressed(SDLK_9) ||
- Input::isKeyPressed(SDLK_0) ||
- Input::isKeyPressed(SDLK_MINUS)) {
+ if ( Input::isKeyPressed(SDL_SCANCODE_1) ||
+ Input::isKeyPressed(SDL_SCANCODE_2) ||
+ Input::isKeyPressed(SDL_SCANCODE_3) ||
+ Input::isKeyPressed(SDL_SCANCODE_4) ||
+ Input::isKeyPressed(SDL_SCANCODE_5) ||
+ Input::isKeyPressed(SDL_SCANCODE_6) ||
+ Input::isKeyPressed(SDL_SCANCODE_7) ||
+ Input::isKeyPressed(SDL_SCANCODE_8) ||
+ Input::isKeyPressed(SDL_SCANCODE_9) ||
+ Input::isKeyPressed(SDL_SCANCODE_0) ||
+ Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
int whichend;
- if (Input::isKeyPressed(SDLK_1)) whichend = 1;
- if (Input::isKeyPressed(SDLK_2)) whichend = 2;
- if (Input::isKeyPressed(SDLK_3)) whichend = 3;
- if (Input::isKeyPressed(SDLK_4)) whichend = 4;
- if (Input::isKeyPressed(SDLK_5)) whichend = 5;
- if (Input::isKeyPressed(SDLK_6)) whichend = 6;
- if (Input::isKeyPressed(SDLK_7)) whichend = 7;
- if (Input::isKeyPressed(SDLK_8)) whichend = 8;
- if (Input::isKeyPressed(SDLK_9)) whichend = 9;
- if (Input::isKeyPressed(SDLK_0)) whichend = 0;
- if (Input::isKeyPressed(SDLK_MINUS))
+ if (Input::isKeyPressed(SDL_SCANCODE_1)) whichend = 1;
+ if (Input::isKeyPressed(SDL_SCANCODE_2)) whichend = 2;
+ if (Input::isKeyPressed(SDL_SCANCODE_3)) whichend = 3;
+ if (Input::isKeyPressed(SDL_SCANCODE_4)) whichend = 4;
+ if (Input::isKeyPressed(SDL_SCANCODE_5)) whichend = 5;
+ if (Input::isKeyPressed(SDL_SCANCODE_6)) whichend = 6;
+ if (Input::isKeyPressed(SDL_SCANCODE_7)) whichend = 7;
+ if (Input::isKeyPressed(SDL_SCANCODE_8)) whichend = 8;
+ if (Input::isKeyPressed(SDL_SCANCODE_9)) whichend = 9;
+ if (Input::isKeyPressed(SDL_SCANCODE_0)) whichend = 0;
+ if (Input::isKeyPressed(SDL_SCANCODE_MINUS))
whichend = -1;
if (whichend != -1) {
participantfocus[whichdialogue][indialogue] = whichend;
}
}
//TODO: should these be KeyDown or KeyPressed?
- if ( Input::isKeyDown(SDLK_KP1) ||
- Input::isKeyDown(SDLK_KP2) ||
- Input::isKeyDown(SDLK_KP3) ||
- Input::isKeyDown(SDLK_KP4) ||
- Input::isKeyDown(SDLK_KP5) ||
- Input::isKeyDown(SDLK_KP6) ||
- Input::isKeyDown(SDLK_KP7) ||
- Input::isKeyDown(SDLK_KP8) ||
- Input::isKeyDown(SDLK_KP9) ||
- Input::isKeyDown(SDLK_KP0)) {
+ if ( Input::isKeyDown(SDL_SCANCODE_KP_1) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_2) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_3) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_4) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_5) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_6) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_7) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_8) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_9) ||
+ Input::isKeyDown(SDL_SCANCODE_KP_0)) {
int whichend;
- if (Input::isKeyDown(SDLK_KP1)) whichend = 1;
- if (Input::isKeyDown(SDLK_KP2)) whichend = 2;
- if (Input::isKeyDown(SDLK_KP3)) whichend = 3;
- if (Input::isKeyDown(SDLK_KP4)) whichend = 4;
- if (Input::isKeyDown(SDLK_KP5)) whichend = 5;
- if (Input::isKeyDown(SDLK_KP6)) whichend = 6;
- if (Input::isKeyDown(SDLK_KP7)) whichend = 7;
- if (Input::isKeyDown(SDLK_KP8)) whichend = 8;
- if (Input::isKeyDown(SDLK_KP9)) whichend = 9;
- if (Input::isKeyDown(SDLK_KP0)) whichend = 0;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_1)) whichend = 1;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_2)) whichend = 2;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_3)) whichend = 3;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_4)) whichend = 4;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_5)) whichend = 5;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_6)) whichend = 6;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_7)) whichend = 7;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_8)) whichend = 8;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_9)) whichend = 9;
+ if (Input::isKeyDown(SDL_SCANCODE_KP_0)) whichend = 0;
participantfacing[whichdialogue][indialogue][whichend] = facing;
}
if (indialogue >= numdialogueboxes[whichdialogue]) {
yaw = dialoguecamerayaw[whichdialogue][indialogue];
pitch = dialoguecamerapitch[whichdialogue][indialogue];
if (dialoguetime > 0.5)
- if ( Input::isKeyPressed(SDLK_1) ||
- Input::isKeyPressed(SDLK_2) ||
- Input::isKeyPressed(SDLK_3) ||
- Input::isKeyPressed(SDLK_4) ||
- Input::isKeyPressed(SDLK_5) ||
- Input::isKeyPressed(SDLK_6) ||
- Input::isKeyPressed(SDLK_7) ||
- Input::isKeyPressed(SDLK_8) ||
- Input::isKeyPressed(SDLK_9) ||
- Input::isKeyPressed(SDLK_0) ||
- Input::isKeyPressed(SDLK_MINUS) ||
+ if ( Input::isKeyPressed(SDL_SCANCODE_1) ||
+ Input::isKeyPressed(SDL_SCANCODE_2) ||
+ Input::isKeyPressed(SDL_SCANCODE_3) ||
+ Input::isKeyPressed(SDL_SCANCODE_4) ||
+ Input::isKeyPressed(SDL_SCANCODE_5) ||
+ Input::isKeyPressed(SDL_SCANCODE_6) ||
+ Input::isKeyPressed(SDL_SCANCODE_7) ||
+ Input::isKeyPressed(SDL_SCANCODE_8) ||
+ Input::isKeyPressed(SDL_SCANCODE_9) ||
+ Input::isKeyPressed(SDL_SCANCODE_0) ||
+ Input::isKeyPressed(SDL_SCANCODE_MINUS) ||
Input::isKeyPressed(attackkey)) {
indialogue++;
if (indialogue < numdialogueboxes[whichdialogue]) {
static bool respawnkeydown;
if (!editorenabled &&
(whichlevel != -2 &&
- (Input::isKeyDown(SDLK_z) &&
- Input::isKeyDown(SDLK_LMETA) &&
+ (Input::isKeyDown(SDL_SCANCODE_Z) &&
+ Input::isKeyDown(SDL_SCANCODE_LGUI) &&
debugmode) ||
(Input::isKeyDown(jumpkey) &&
!respawnkeydown &&
}
}
- if (Input::isKeyPressed(SDLK_F1))
+ if (Input::isKeyPressed(SDL_SCANCODE_F1))
Screenshot();
}
Terrain terrain;
float sps = 0;
-SDL_Surface *sdlscreen;
+SDL_Window *sdlwindow;
int kTextureSize = 0;
int detail = 0;
extern bool keyboardfrozen;
-bool keyDown[SDLK_LAST + 6];
-bool keyPressed[SDLK_LAST + 6];
+bool keyDown[SDL_NUM_SCANCODES + 6];
+bool keyPressed[SDL_NUM_SCANCODES + 6];
void Input::Tick()
{
SDL_PumpEvents();
- Uint8 *keyState = SDL_GetKeyState(NULL);
- for (int i = 0; i < SDLK_LAST; i++) {
+ int numkeys;
+ const Uint8 *keyState = SDL_GetKeyboardState(&numkeys);
+ for (int i = 0; i < numkeys; i++) {
keyPressed[i] = !keyDown[i] && keyState[i];
keyDown[i] = keyState[i];
}
Uint8 mb = SDL_GetMouseState(NULL, NULL);
for (int i = 1; i < 6; i++) {
- keyPressed[SDLK_LAST + i] = !keyDown[SDLK_LAST + i] && (mb & SDL_BUTTON(i));
- keyDown[SDLK_LAST + i] = (mb & SDL_BUTTON(i));
+ keyPressed[SDL_NUM_SCANCODES + i] = !keyDown[SDL_NUM_SCANCODES + i] && (mb & SDL_BUTTON(i));
+ keyDown[SDL_NUM_SCANCODES + i] = (mb & SDL_BUTTON(i));
}
}
bool Input::isKeyDown(int k)
{
- if (keyboardfrozen || k >= SDLK_LAST + 6) // really useful? check that.
+ if (keyboardfrozen || k >= SDL_NUM_SCANCODES + 6) // really useful? check that.
return false;
return keyDown[k];
}
bool Input::isKeyPressed(int k)
{
- if (keyboardfrozen || k >= SDLK_LAST + 6)
+ if (keyboardfrozen || k >= SDL_NUM_SCANCODES + 6)
return false;
return keyPressed[k];
}
const char* Input::keyToChar(unsigned short i)
{
- if (i < SDLK_LAST)
- return SDL_GetKeyName(SDLKey(i));
- else if (i == SDLK_LAST + SDL_BUTTON_LEFT)
+ if (i < SDL_NUM_SCANCODES)
+ return SDL_GetScancodeName(SDL_Scancode(i));
+ else if (i == MOUSEBUTTON1)
return "mouse1";
- else if (i == SDLK_LAST + SDL_BUTTON_RIGHT)
+ else if (i == MOUSEBUTTON2)
return "mouse2";
- else if (i == SDLK_LAST + SDL_BUTTON_MIDDLE)
+ else if (i == MOUSEBUTTON3)
return "mouse3";
else
return "unknown";
unsigned short Input::CharToKey(const char* which)
{
- for (unsigned short i = 0; i < SDLK_LAST; i++) {
- if (!strcasecmp(which, SDL_GetKeyName(SDLKey(i))))
+ for (unsigned short i = 0; i < SDL_NUM_SCANCODES; i++) {
+ if (!strcasecmp(which, SDL_GetScancodeName(SDL_Scancode(i))))
return i;
}
if (!strcasecmp(which, "mouse1")) {
if (!strcasecmp(which, "mouse2")) {
return MOUSEBUTTON2;
}
- return SDLK_LAST;
+ if (!strcasecmp(which, "mouse3")) {
+ return MOUSEBUTTON3;
+ }
+ return SDL_NUM_SCANCODES;
}
Boolean Input::MouseClicked()
{
- return isKeyPressed(SDLK_LAST + SDL_BUTTON_LEFT);
+ return isKeyPressed(SDL_NUM_SCANCODES + SDL_BUTTON_LEFT);
}
#include "Game.h"
/**> CONSTANT DECLARATIONS <**/
-#define MOUSEBUTTON1 SDLK_LAST+SDL_BUTTON_LEFT
-#define MOUSEBUTTON2 SDLK_LAST+SDL_BUTTON_RIGHT
+#define MOUSEBUTTON1 (SDL_NUM_SCANCODES + SDL_BUTTON_LEFT)
+#define MOUSEBUTTON2 (SDL_NUM_SCANCODES + SDL_BUTTON_RIGHT)
+#define MOUSEBUTTON3 (SDL_NUM_SCANCODES + SDL_BUTTON_MIDDLE)
/**> FUNCTION PROTOTYPES <**/
class Input
#include "win-res/resource.h"
#endif
+extern SDL_Window *sdlwindow;
+
using namespace std;
SDL_Rect **resolutions = NULL;
-static SDL_Rect rect_1024_768 = { 0, 0, 1024, 768 };
-static SDL_Rect rect_800_600 = { 0, 0, 800, 600 };
-static SDL_Rect rect_640_480 = { 0, 0, 640, 480 };
-static SDL_Rect *hardcoded_resolutions[] = {
- &rect_1024_768,
- &rect_800_600,
- &rect_640_480,
- NULL
-};
Boolean SetUp ();
void DoUpdate ();
static void toggleFullscreen()
{
- if (!SDL_WM_ToggleFullScreen(SDL_GetVideoSurface())) {
- SDL_Surface* screen = SDL_GetVideoSurface();
- Uint32 flags = screen->flags;
- screen = SDL_SetVideoMode(0, 0, 0, flags ^ SDL_FULLSCREEN);
- if (!screen)
- screen = SDL_SetVideoMode(0, 0, 0, flags);
- if (!screen)
- exit(1);
- //reload opengl state
- initGL();
- Texture::reloadAll();
- if (text)
- text->BuildFont();
- if (firstload) {
- screentexture = 0;
- LoadScreenTexture();
- }
- screentexture2 = 0;
+ Uint32 flags = SDL_GetWindowFlags(sdlwindow);
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ flags &= ~SDL_WINDOW_FULLSCREEN;
+ } else {
+ flags |= SDL_WINDOW_FULLSCREEN;
}
+ SDL_SetWindowFullscreen(sdlwindow, flags);
}
-static void sdlEventProc(const SDL_Event &e)
+static SDL_bool sdlEventProc(const SDL_Event &e)
{
switch (e.type) {
- case SDL_MOUSEMOTION:
- deltah += e.motion.xrel;
- deltav += e.motion.yrel;
+ case SDL_QUIT:
+ return SDL_FALSE;
+
+ case SDL_WINDOWEVENT:
+ if (e.window.event == SDL_WINDOWEVENT_CLOSE) {
+ return SDL_FALSE;
+ }
break;
- case SDL_KEYDOWN:
- if ((e.key.keysym.sym == SDLK_g) &&
- (e.key.keysym.mod & KMOD_CTRL) &&
- !(SDL_GetVideoSurface()->flags & SDL_FULLSCREEN) ) {
- SDL_WM_GrabInput( ((SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON) ? SDL_GRAB_OFF : SDL_GRAB_ON) );
- } else if ( (e.key.keysym.sym == SDLK_RETURN) && (e.key.keysym.mod & KMOD_ALT) ) {
- toggleFullscreen();
- }
+ case SDL_MOUSEMOTION:
+ deltah += e.motion.xrel;
+ deltav += e.motion.yrel;
+ break;
+
+ case SDL_KEYDOWN:
+ if ((e.key.keysym.scancode == SDL_SCANCODE_G) &&
+ (e.key.keysym.mod & KMOD_CTRL)) {
+ SDL_bool mode = SDL_TRUE;
+ if ((SDL_GetWindowFlags(sdlwindow) & SDL_WINDOW_FULLSCREEN) == 0)
+ mode = (SDL_GetWindowGrab(sdlwindow) ? SDL_FALSE : SDL_TRUE);
+ SDL_SetWindowGrab(sdlwindow, mode);
+ SDL_SetRelativeMouseMode(mode);
+ } else if ( (e.key.keysym.scancode == SDL_SCANCODE_RETURN) && (e.key.keysym.mod & KMOD_ALT) ) {
+ toggleFullscreen();
+ }
break;
}
+ return SDL_TRUE;
}
DefaultSettings();
+ const int displayIdx = 0; // !!! FIXME: other monitors?
+
if (!SDL_WasInit(SDL_INIT_VIDEO))
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
return false;
}
- SDL_Rect **res = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL);
- if ( (res == NULL) || (res == ((SDL_Rect **) - 1)) || (res[0] == NULL) || (res[0]->w < 640) || (res[0]->h < 480) )
- res = hardcoded_resolutions;
+ int count = 0;
+ const int nummodes = SDL_GetNumDisplayModes(displayIdx);
+ for (int i = 0; i < nummodes; i++)
+ {
+ SDL_DisplayMode mode;
+ if (SDL_GetDisplayMode(displayIdx, i, &mode) == -1)
+ continue;
+ if ((mode.w < 640) || (mode.h < 480))
+ continue; // sane lower limit.
+ count++;
+ }
- // reverse list (it was sorted biggest to smallest by SDL)...
- int count;
- for (count = 0; res[count]; count++) {
- if ((res[count]->w < 640) || (res[count]->h < 480))
- break; // sane lower limit.
+ if (count == 0) {
+ const std::string error = "No suitable video resolutions found.";
+ cerr << error << endl;
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Lugaru init failed!", error.c_str(), NULL);
+ SDL_Quit();
+ return false;
}
static SDL_Rect *resolutions_block = NULL;
resolutions[count--] = NULL;
for (int i = 0; count >= 0; i++, count--) {
- memcpy(&resolutions_block[count], res[i], sizeof (SDL_Rect));
+ /* FIXME - Pretty sure this should use nummodes and not count */
+ SDL_DisplayMode mode;
+ if (SDL_GetDisplayMode(displayIdx, i, &mode) == -1)
+ continue;
+ if ((mode.w < 640) || (mode.h < 480))
+ continue; // sane lower limit.
+ resolutions_block[count].x = resolutions_block[count].y = 0;
+ resolutions_block[count].w = mode.w;
+ resolutions_block[count].h = mode.h;
resolutions[count] = &resolutions_block[count];
}
printf(" %d x %d\n", (int) resolutions[i]->w, (int) resolutions[i]->h);
}
- Uint32 sdlflags = SDL_OPENGL;
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
+ Uint32 sdlflags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
if (!cmdline("windowed"))
- sdlflags |= SDL_FULLSCREEN;
-
- SDL_WM_SetCaption("Lugaru", "Lugaru");
+ sdlflags |= SDL_WINDOW_FULLSCREEN;
+ if (!cmdline("nomousegrab"))
+ sdlflags |= SDL_WINDOW_INPUT_GRABBED;
- SDL_ShowCursor(0);
+ sdlwindow = SDL_CreateWindow("Lugaru", SDL_WINDOWPOS_CENTERED_DISPLAY(displayIdx), SDL_WINDOWPOS_CENTERED_DISPLAY(displayIdx),
+ kContextWidth, kContextHeight, sdlflags);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
-#if SDL_VERSION_ATLEAST(1, 2, 10)
- SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, vblsync);
-#endif
-
- if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL) {
- fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+ if (!sdlwindow) {
+ fprintf(stderr, "SDL_CreateWindow() failed: %s\n", SDL_GetError());
fprintf(stderr, "forcing 640x480...\n");
kContextWidth = 640;
kContextHeight = 480;
- if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL) {
- fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+ sdlwindow = SDL_CreateWindow("Lugaru", SDL_WINDOWPOS_CENTERED_DISPLAY(displayIdx), SDL_WINDOWPOS_CENTERED_DISPLAY(displayIdx),
+ kContextWidth, kContextHeight, sdlflags);
+ if (!sdlwindow) {
+ fprintf(stderr, "SDL_CreateWindow() failed: %s\n", SDL_GetError());
fprintf(stderr, "forcing 640x480 windowed mode...\n");
- sdlflags &= ~SDL_FULLSCREEN;
- if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL) {
- fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+ sdlflags &= ~SDL_WINDOW_FULLSCREEN;
+ sdlwindow = SDL_CreateWindow("Lugaru", SDL_WINDOWPOS_CENTERED_DISPLAY(displayIdx), SDL_WINDOWPOS_CENTERED_DISPLAY(displayIdx),
+ kContextWidth, kContextHeight, sdlflags);
+
+ if (!sdlwindow) {
+ fprintf(stderr, "SDL_CreateWindow() failed: %s\n", SDL_GetError());
return false;
}
}
}
- int dblbuf = 0;
- if ((SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &dblbuf) == -1) || (!dblbuf)) {
- fprintf(stderr, "Failed to get double buffered GL context!\n");
+ SDL_GLContext glctx = SDL_GL_CreateContext(sdlwindow);
+ if (!glctx) {
+ fprintf(stderr, "SDL_GL_CreateContext() failed: %s\n", SDL_GetError());
SDL_Quit();
return false;
}
+ SDL_GL_MakeCurrent(sdlwindow, glctx);
+
if (!lookup_all_glsyms()) {
+ fprintf(stderr, "Missing required OpenGL functions.\n");
SDL_Quit();
return false;
}
- if (!cmdline("nomousegrab"))
- SDL_WM_GrabInput(SDL_GRAB_ON);
+ int dblbuf = 0;
+ if ((SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &dblbuf) == -1) || (!dblbuf))
+ {
+ fprintf(stderr, "Failed to get a double-buffered context.\n");
+ SDL_Quit();
+ return false;
+ }
+
+ if (SDL_GL_SetSwapInterval(-1) == -1) // try swap_tear first.
+ SDL_GL_SetSwapInterval(1);
+
+ SDL_ShowCursor(0);
+ SDL_SetWindowGrab(sdlwindow, SDL_TRUE);
+ SDL_SetRelativeMouseMode(SDL_TRUE);
initGL();
static bool IsFocused()
{
- return ((SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0);
+ return ((SDL_GetWindowFlags(sdlwindow) & SDL_WINDOW_INPUT_FOCUS) != 0);
}
if (!waiting) {
// message pump
while ( SDL_PollEvent( &e ) ) {
- if ( e.type == SDL_QUIT ) {
+ if (!sdlEventProc(e)) {
gDone = true;
break;
}
- sdlEventProc(e);
}
}
}
// game is not in focus, give CPU time to other apps by waiting for messages instead of 'peeking'
- SDL_ActiveEvent evt;
- SDL_WaitEvent((SDL_Event*)&evt);
- if (evt.type == SDL_ACTIVEEVENT && evt.gain == 1)
- gameFocused = true;
- else if (evt.type == SDL_QUIT)
- gDone = true;
+ SDL_WaitEvent(0);
}
}
vblsync = 1;
debugmode = 0;
- crouchkey = SDLK_LSHIFT;
- jumpkey = SDLK_SPACE;
- leftkey = SDLK_a;
- forwardkey = SDLK_w;
- backkey = SDLK_s;
- rightkey = SDLK_d;
- drawkey = SDLK_e;
- throwkey = SDLK_q;
+ crouchkey = SDL_SCANCODE_LSHIFT;
+ jumpkey = SDL_SCANCODE_SPACE;
+ leftkey = SDL_SCANCODE_A;
+ forwardkey = SDL_SCANCODE_W;
+ backkey = SDL_SCANCODE_S;
+ rightkey = SDL_SCANCODE_D;
+ drawkey = SDL_SCANCODE_E;
+ throwkey = SDL_SCANCODE_Q;
attackkey = MOUSEBUTTON1;
- consolekey = SDLK_BACKQUOTE;
- chatkey = SDLK_t;
+ consolekey = SDL_SCANCODE_GRAVE;
+ chatkey = SDL_SCANCODE_T;
}
void SaveSettings()
opstream << "\nVolume:\n";
opstream << volume;
opstream << "\nForward key:\n";
- opstream << Input::keyToChar(forwardkey);
+ opstream << forwardkey;
opstream << "\nBack key:\n";
- opstream << Input::keyToChar(backkey);
+ opstream << backkey;
opstream << "\nLeft key:\n";
- opstream << Input::keyToChar(leftkey);
+ opstream << leftkey;
opstream << "\nRight key:\n";
- opstream << Input::keyToChar(rightkey);
+ opstream << rightkey;
opstream << "\nJump key:\n";
- opstream << Input::keyToChar(jumpkey);
+ opstream << jumpkey;
opstream << "\nCrouch key:\n";
- opstream << Input::keyToChar(crouchkey);
+ opstream << crouchkey;
opstream << "\nDraw key:\n";
- opstream << Input::keyToChar(drawkey);
+ opstream << drawkey;
opstream << "\nThrow key:\n";
- opstream << Input::keyToChar(throwkey);
+ opstream << throwkey;
opstream << "\nAttack key:\n";
- opstream << Input::keyToChar(attackkey);
+ opstream << attackkey;
opstream << "\nConsole key:\n";
- opstream << Input::keyToChar(consolekey);
+ opstream << consolekey;
opstream << "\nChat key:\n";
- opstream << Input::keyToChar(chatkey);
+ opstream << chatkey;
opstream << "\nDamage bar:\n";
opstream << showdamagebar;
opstream << "\nStereoMode:\n";
} else if ( !strncmp(setting, "Volume", 6) ) {
ipstream >> volume;
} else if ( !strncmp(setting, "Forward key", 11) ) {
- ipstream.getline( string, sizeof(string) );
- forwardkey = Input::CharToKey(string);
+ ipstream >> forwardkey;
} else if ( !strncmp(setting, "Back key", 8) ) {
- ipstream.getline( string, sizeof(string) );
- backkey = Input::CharToKey(string);
+ ipstream >> backkey;
} else if ( !strncmp(setting, "Left key", 8) ) {
- ipstream.getline( string, sizeof(string) );
- leftkey = Input::CharToKey(string);
+ ipstream >> leftkey;
} else if ( !strncmp(setting, "Right key", 9) ) {
- ipstream.getline( string, sizeof(string) );
- rightkey = Input::CharToKey(string);
+ ipstream >> rightkey;
} else if ( !strncmp(setting, "Jump key", 8) ) {
- ipstream.getline( string, sizeof(string) );
- jumpkey = Input::CharToKey(string);
+ ipstream >> jumpkey;
} else if ( !strncmp(setting, "Crouch key", 10) ) {
- ipstream.getline( string, sizeof(string) );
- crouchkey = Input::CharToKey(string);
+ ipstream >> crouchkey;
} else if ( !strncmp(setting, "Draw key", 8) ) {
- ipstream.getline( string, sizeof(string) );
- drawkey = Input::CharToKey(string);
+ ipstream >> drawkey;
} else if ( !strncmp(setting, "Throw key", 9) ) {
- ipstream.getline( string, sizeof(string) );
- throwkey = Input::CharToKey(string);
+ ipstream >> throwkey;
} else if ( !strncmp(setting, "Attack key", 10) ) {
- ipstream.getline( string, sizeof(string) );
- attackkey = Input::CharToKey(string);
+ ipstream >> attackkey;
} else if ( !strncmp(setting, "Console key", 11) ) {
- ipstream.getline( string, sizeof(string) );
- consolekey = Input::CharToKey(string);
+ ipstream >> consolekey;
} else if ( !strncmp(setting, "Chat key", 8) ) {
- ipstream.getline( string, sizeof(string) );
- chatkey = Input::CharToKey(string);
+ ipstream >> chatkey;
} else if ( !strncmp(setting, "Damage bar", 10) ) {
ipstream >> showdamagebar;
} else if ( !strncmp(setting, "StereoMode", 10) ) {