/*
Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
#include "Audio/openal_wrapper.hpp"
#include "Graphic/gamegl.hpp"
-#include "MacCompatibility.hpp"
+#include "Platform/Platform.hpp"
#include "User/Settings.hpp"
+#include "Version.hpp"
#include <fstream>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string.h>
-#include <zlib.h>
using namespace Game;
#ifdef WIN32
-#include "win-res/resource.hpp"
#include <shellapi.h>
#include <windows.h>
+#else
+#include <unistd.h>
#endif
extern float multiplier;
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)
+ 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)) {
DefaultSettings();
- if (!SDL_WasInit(SDL_INIT_VIDEO))
+ if (!SDL_WasInit(SDL_INIT_VIDEO)) {
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
return false;
}
+ }
if (!LoadSettings()) {
fprintf(stderr, "Failed to load config, creating default\n");
SaveSettings();
for (int displayIdx = 0; displayIdx < SDL_GetNumVideoDisplays(); ++displayIdx) {
for (int i = 0; i < SDL_GetNumDisplayModes(displayIdx); ++i) {
SDL_DisplayMode mode;
- if (SDL_GetDisplayMode(displayIdx, i, &mode) == -1)
+ if (SDL_GetDisplayMode(displayIdx, i, &mode) == -1) {
continue;
- if ((mode.w < 640) || (mode.h < 480))
+ }
+ if ((mode.w < 640) || (mode.h < 480)) {
continue; // sane lower limit.
+ }
pair<int, int> resolution(mode.w, mode.h);
resolutions.insert(resolution);
}
return false;
}
- if (SDL_GL_SetSwapInterval(-1) == -1) // try swap_tear first.
+ if (SDL_GL_SetSwapInterval(-1) == -1) { // try swap_tear first.
SDL_GL_SetSwapInterval(1);
+ }
SDL_ShowCursor(0);
if (!commandLineOptions[NOMOUSEGRAB].last()->type()) {
deltav *= usermousesensitivity;
mousecoordh += deltah;
mousecoordv += deltav;
- if (mousecoordh < 0)
+ if (mousecoordh < 0) {
mousecoordh = 0;
- else if (mousecoordh >= kContextWidth)
+ } else if (mousecoordh >= kContextWidth) {
mousecoordh = kContextWidth - 1;
- if (mousecoordv < 0)
+ }
+ if (mousecoordv < 0) {
mousecoordv = 0;
- else if (mousecoordv >= kContextHeight)
+ } else if (mousecoordv >= kContextHeight) {
mousecoordv = kContextHeight - 1;
+ }
}
}
AbsoluteTime currTime = UpTime();
double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime);
- if (0 > deltaTime) // if negative microseconds
+ if (0 > deltaTime) { // if negative microseconds
deltaTime /= -1000000.0;
- else // else milliseconds
+ } else { // else milliseconds
deltaTime /= 1000.0;
+ }
multiplier = deltaTime;
- if (multiplier < .001)
+ if (multiplier < .001) {
multiplier = .001;
- if (multiplier > 10)
+ }
+ if (multiplier > 10) {
multiplier = 10;
- if (update)
+ }
+ if (update) {
frametime = currTime; // reset for next time interval
+ }
deltaTime = (float)AbsoluteDeltaToDuration(currTime, time);
- if (0 > deltaTime) // if negative microseconds
+ if (0 > deltaTime) { // if negative microseconds
deltaTime /= -1000000.0;
- else // else milliseconds
+ } else { // else milliseconds
deltaTime /= 1000.0;
+ }
frames++;
if (0.001 <= deltaTime) { // has update interval passed
if (update) {
static float oldmult;
DoFrameRate(1);
- if (multiplier > .6)
+ if (multiplier > .6) {
multiplier = .6;
+ }
fps = 1 / multiplier;
count = multiplier * sps;
- if (count < 2)
+ if (count < 2) {
count = 2;
+ }
realmultiplier = multiplier;
multiplier *= gamespeed;
- if (difficulty == 1)
+ if (difficulty == 1) {
multiplier *= .9;
- if (difficulty == 0)
+ }
+ if (difficulty == 0) {
multiplier *= .8;
+ }
- if (loading == 4)
+ if (loading == 4) {
multiplier *= .00001;
- if (slomo && !mainmenu)
+ }
+ if (slomo && !mainmenu) {
multiplier *= slomospeed;
+ }
oldmult = multiplier;
multiplier /= (float)count;
do {
size_t size;
ptr = strchr(start, ':'); /* find next $PATH separator. */
- if (ptr)
+ if (ptr) {
*ptr = '\0';
-
+ }
size = strlen(start) + strlen(bin) + 2;
if (size > alloc_size) {
char* x = (char*)realloc(exe, size);
if (x == NULL) {
- if (exe != NULL)
+ if (exe != NULL) {
free(exe);
+ }
return (NULL);
} /* if */
/* build full binary path... */
strcpy(exe, start);
- if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/'))
+ if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/')) {
strcat(exe, "/");
+ }
strcat(exe, bin);
if (access(exe, X_OK) == 0) { /* Exists as executable? We're done. */
start = ptr + 1; /* start points to beginning of next element. */
} while (ptr != NULL);
- if (exe != NULL)
+ if (exe != NULL) {
free(exe);
+ }
return (NULL); /* doesn't exist in path. */
} /* findBinaryInPath */
if (strchr(argv0, '/')) {
retval = strdup(argv0);
- if (retval)
+ if (retval) {
*((char*)strrchr(retval, '/')) = '\0';
+ }
return (retval);
}
envr = getenv("PATH");
- if (!envr)
+ if (!envr) {
return NULL;
+ }
envr = strdup(envr);
- if (!envr)
+ if (!envr) {
return NULL;
+ }
retval = findBinaryInPath(argv0, envr);
free(envr);
return (retval);
{
{ UNKNOWN, 0, "", "", option::Arg::None, "USAGE: lugaru [options]\n\n"
"Options:" },
+ { VERSION, 0, "v", "version", option::Arg::None, " -v, --version Print version and exit." },
{ HELP, 0, "h", "help", option::Arg::None, " -h, --help Print usage and exit." },
{ FULLSCREEN, 1, "f", "fullscreen", option::Arg::None, " -f, --fullscreen Start the game in fullscreen mode." },
{ FULLSCREEN, 0, "w", "windowed", option::Arg::None, " -w, --windowed Start the game in windowed mode (default)." },
return 1;
}
+ // Always start by printing the version and info to the stdout
+ std::cout << "--------------------------------------------------------------------------\n"
+ << "Lugaru HD: The Rabbit's Foot, by Wolfire Games and the OSS Lugaru project.\n\n"
+ << "Licensed under the GPL 2.0+ and CC-BY-SA 3.0 and 4.0 licenses.\n"
+ << "More information, updates and bug reports at http://osslugaru.gitlab.io\n"
+ << std::endl;
+
+ std::cout << "Version " + VERSION_STRING + " -- " + VERSION_BUILD_TYPE + " build\n"
+ << "--------------------------------------------------------------------------\n"
+ << std::endl;
+
+ if (commandLineOptions[VERSION]) {
+ // That was enough, quit.
+ delete[] commandLineOptionsBuffer;
+ return 0;
+ }
+
if (commandLineOptions[HELP]) {
option::printUsage(std::cout, usage);
delete[] commandLineOptionsBuffer;