1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-01 10:33:32 +02:00
VVVVVV/desktop_version/src/main.cpp

699 lines
18 KiB
C++
Raw Normal View History

2020-01-01 21:29:24 +01:00
#include <SDL.h>
#include "SoundSystem.h"
#include "UtilityClass.h"
#include "Game.h"
#include "Graphics.h"
#include "KeyPoll.h"
#include "Render.h"
2020-01-01 21:29:24 +01:00
#include "Tower.h"
#include "WarpClass.h"
#include "Labclass.h"
#include "Finalclass.h"
#include "Map.h"
#include "Screen.h"
#include "Script.h"
#include "Logic.h"
#include "Input.h"
#include "editor.h"
#include "preloader.h"
#include "FileSystemUtils.h"
#include "Network.h"
#include <stdio.h>
#include <string.h>
scriptclass script;
#if !defined(NO_CUSTOM_LEVELS)
std::vector<edentities> edentity;
editorclass ed;
#endif
2020-01-01 21:29:24 +01:00
Allow using help/graphics/music/game/key/map/obj everywhere This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and `obj` essentially static global objects that can be used everywhere. This is useful in case we ever need to add a new function in the future, so we don't have to bother with passing a new argument in which means we have to pass a new argument in to the function that calls that function which means having to pass a new argument into the function that calls THAT function, etc. which is a real headache when working on fan mods of the source code. Note that this changes NONE of the existing function signatures, it merely just makes those variables accessible everywhere in the same way `script` and `ed` are. Also note that some classes had to be initialized after the filesystem was initialized, but C++ would keep initializing them before the filesystem got initialized, because I *had* to put them at the top of `main.cpp`, or else they wouldn't be global variables. The only way to work around this was to use entityclass's initialization style (which I'm pretty sure entityclass of all things doesn't need to be initialized this way), where you actually initialize the class in an `init()` function, and so then you do `graphics.init()` after the filesystem initialization, AFTER doing `Graphics graphics` up at the top. I've had to do this for `graphics` (but only because its child GraphicsResources `grphx` needs to be initialized this way), `music`, and `game`. I don't think this will affect anything. Other than that, `help`, `key`, and `map` are still using the C++-intended method of having ClassName::ClassName() functions.
2020-01-29 08:35:03 +01:00
UtilityClass help;
Graphics graphics;
musicclass music;
Game game;
KeyPoll key;
mapclass map;
entityclass obj;
Screen gameScreen;
Allow using help/graphics/music/game/key/map/obj everywhere This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and `obj` essentially static global objects that can be used everywhere. This is useful in case we ever need to add a new function in the future, so we don't have to bother with passing a new argument in which means we have to pass a new argument in to the function that calls that function which means having to pass a new argument into the function that calls THAT function, etc. which is a real headache when working on fan mods of the source code. Note that this changes NONE of the existing function signatures, it merely just makes those variables accessible everywhere in the same way `script` and `ed` are. Also note that some classes had to be initialized after the filesystem was initialized, but C++ would keep initializing them before the filesystem got initialized, because I *had* to put them at the top of `main.cpp`, or else they wouldn't be global variables. The only way to work around this was to use entityclass's initialization style (which I'm pretty sure entityclass of all things doesn't need to be initialized this way), where you actually initialize the class in an `init()` function, and so then you do `graphics.init()` after the filesystem initialization, AFTER doing `Graphics graphics` up at the top. I've had to do this for `graphics` (but only because its child GraphicsResources `grphx` needs to be initialized this way), `music`, and `game`. I don't think this will affect anything. Other than that, `help`, `key`, and `map` are still using the C++-intended method of having ClassName::ClassName() functions.
2020-01-29 08:35:03 +01:00
bool startinplaytest = false;
bool savefileplaytest = false;
int savex = 0;
int savey = 0;
int saverx = 0;
int savery = 0;
int savegc = 0;
int savemusic = 0;
std::string playassets;
std::string playtestname;
volatile Uint32 time_ = 0;
volatile Uint32 timePrev = 0;
volatile Uint32 accumulator = 0;
volatile Uint32 f_time = 0;
volatile Uint32 f_timePrev = 0;
void inline deltaloop();
void inline fixedloop();
2020-01-01 21:29:24 +01:00
int main(int argc, char *argv[])
{
char* baseDir = NULL;
char* assetsPath = NULL;
for (int i = 1; i < argc; ++i)
{
#define ARG(name) (strcmp(argv[i], name) == 0)
#define ARG_INNER(code) \
if (i + 1 < argc) \
{ \
code \
} \
else \
{ \
printf("%s option requires one argument.\n", argv[i]); \
return 1; \
}
if (ARG("-renderer"))
{
ARG_INNER({
i++;
SDL_SetHintWithPriority(SDL_HINT_RENDER_DRIVER, argv[i], SDL_HINT_OVERRIDE);
})
}
else if (ARG("-basedir"))
{
ARG_INNER({
i++;
baseDir = argv[i];
})
}
else if (ARG("-assets"))
{
ARG_INNER({
i++;
assetsPath = argv[i];
})
}
else if (ARG("-playing") || ARG("-p"))
{
ARG_INNER({
i++;
startinplaytest = true;
playtestname = std::string("levels/");
playtestname.append(argv[i]);
playtestname.append(std::string(".vvvvvv"));
})
}
else if (ARG("-playx") || ARG("-playy") ||
ARG("-playrx") || ARG("-playry") ||
ARG("-playgc") || ARG("-playmusic"))
{
ARG_INNER({
savefileplaytest = true;
int v = std::atoi(argv[i+1]);
if (ARG("-playx")) savex = v;
else if (ARG("-playy")) savey = v;
else if (ARG("-playrx")) saverx = v;
else if (ARG("-playry")) savery = v;
else if (ARG("-playgc")) savegc = v;
else if (ARG("-playmusic")) savemusic = v;
i++;
})
}
else if (ARG("-playassets"))
{
ARG_INNER({
i++;
// Even if this is a directory, FILESYSTEM_mountassets() expects '.vvvvvv' on the end
playassets = "levels/" + std::string(argv[i]) + ".vvvvvv";
})
}
#undef ARG_INNER
#undef ARG
}
if(!FILESYSTEM_init(argv[0], baseDir, assetsPath))
2020-01-01 21:29:24 +01:00
{
puts("Unable to initialize filesystem!");
return 1;
2020-01-01 21:29:24 +01:00
}
SDL_Init(
SDL_INIT_VIDEO |
SDL_INIT_AUDIO |
SDL_INIT_JOYSTICK |
SDL_INIT_GAMECONTROLLER
);
2020-01-01 21:29:24 +01:00
NETWORK_init();
printf("\t\t\n");
printf("\t\t\n");
printf("\t\t VVVVVV\n");
printf("\t\t\n");
printf("\t\t\n");
printf("\t\t 8888888888888888 \n");
printf("\t\t88888888888888888888\n");
printf("\t\t888888 8888 88\n");
printf("\t\t888888 8888 88\n");
printf("\t\t88888888888888888888\n");
printf("\t\t88888888888888888888\n");
printf("\t\t888888 88\n");
printf("\t\t88888888 8888\n");
printf("\t\t 8888888888888888 \n");
printf("\t\t 88888888 \n");
printf("\t\t 8888888888888888 \n");
printf("\t\t88888888888888888888\n");
printf("\t\t88888888888888888888\n");
printf("\t\t88888888888888888888\n");
printf("\t\t8888 88888888 8888\n");
printf("\t\t8888 88888888 8888\n");
printf("\t\t 888888888888 \n");
printf("\t\t 8888 8888 \n");
printf("\t\t 888888 888888 \n");
printf("\t\t 888888 888888 \n");
printf("\t\t 888888 888888 \n");
printf("\t\t\n");
printf("\t\t\n");
2020-01-01 21:29:24 +01:00
//Set up screen
// Load Ini
Allow using help/graphics/music/game/key/map/obj everywhere This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and `obj` essentially static global objects that can be used everywhere. This is useful in case we ever need to add a new function in the future, so we don't have to bother with passing a new argument in which means we have to pass a new argument in to the function that calls that function which means having to pass a new argument into the function that calls THAT function, etc. which is a real headache when working on fan mods of the source code. Note that this changes NONE of the existing function signatures, it merely just makes those variables accessible everywhere in the same way `script` and `ed` are. Also note that some classes had to be initialized after the filesystem was initialized, but C++ would keep initializing them before the filesystem got initialized, because I *had* to put them at the top of `main.cpp`, or else they wouldn't be global variables. The only way to work around this was to use entityclass's initialization style (which I'm pretty sure entityclass of all things doesn't need to be initialized this way), where you actually initialize the class in an `init()` function, and so then you do `graphics.init()` after the filesystem initialization, AFTER doing `Graphics graphics` up at the top. I've had to do this for `graphics` (but only because its child GraphicsResources `grphx` needs to be initialized this way), `music`, and `game`. I don't think this will affect anything. Other than that, `help`, `key`, and `map` are still using the C++-intended method of having ClassName::ClassName() functions.
2020-01-29 08:35:03 +01:00
graphics.init();
2020-01-01 21:29:24 +01:00
Allow using help/graphics/music/game/key/map/obj everywhere This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and `obj` essentially static global objects that can be used everywhere. This is useful in case we ever need to add a new function in the future, so we don't have to bother with passing a new argument in which means we have to pass a new argument in to the function that calls that function which means having to pass a new argument into the function that calls THAT function, etc. which is a real headache when working on fan mods of the source code. Note that this changes NONE of the existing function signatures, it merely just makes those variables accessible everywhere in the same way `script` and `ed` are. Also note that some classes had to be initialized after the filesystem was initialized, but C++ would keep initializing them before the filesystem got initialized, because I *had* to put them at the top of `main.cpp`, or else they wouldn't be global variables. The only way to work around this was to use entityclass's initialization style (which I'm pretty sure entityclass of all things doesn't need to be initialized this way), where you actually initialize the class in an `init()` function, and so then you do `graphics.init()` after the filesystem initialization, AFTER doing `Graphics graphics` up at the top. I've had to do this for `graphics` (but only because its child GraphicsResources `grphx` needs to be initialized this way), `music`, and `game`. I don't think this will affect anything. Other than that, `help`, `key`, and `map` are still using the C++-intended method of having ClassName::ClassName() functions.
2020-01-29 08:35:03 +01:00
game.init();
2020-01-01 21:29:24 +01:00
// This loads music too...
graphics.reloadresources();
2020-01-01 21:29:24 +01:00
game.gamestate = PRELOADER;
game.menustart = false;
game.mainmenu = 0;
map.ypos = (700-29) * 8;
map.bypos = map.ypos / 2;
//Moved screensetting init here from main menu V2.1
int width = 320;
int height = 240;
bool vsync = false;
game.loadstats(&width, &height, &vsync);
gameScreen.init(
width,
height,
game.fullscreen,
vsync,
game.stretchMode,
game.useLinearFilter,
game.fullScreenEffect_badSignal
);
graphics.screenbuffer = &gameScreen;
2020-01-01 21:29:24 +01:00
const SDL_PixelFormat* fmt = gameScreen.GetFormat();
#define CREATE_SURFACE(w, h) \
SDL_CreateRGBSurface( \
SDL_SWSURFACE, \
w, h, \
fmt->BitsPerPixel, \
fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask \
)
graphics.backBuffer = CREATE_SURFACE(320, 240);
2020-01-01 21:29:24 +01:00
SDL_SetSurfaceBlendMode(graphics.backBuffer, SDL_BLENDMODE_NONE);
graphics.footerbuffer = CREATE_SURFACE(320, 10);
SDL_SetSurfaceBlendMode(graphics.footerbuffer, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(graphics.footerbuffer, 127);
FillRect(graphics.footerbuffer, SDL_MapRGB(fmt, 0, 0, 0));
graphics.ghostbuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.ghostbuffer, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(graphics.ghostbuffer, 127);
2020-01-01 21:29:24 +01:00
graphics.Makebfont();
graphics.foregroundBuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.foregroundBuffer, SDL_BLENDMODE_NONE);
2020-01-01 21:29:24 +01:00
graphics.menubuffer = CREATE_SURFACE(320, 240);
2020-01-01 21:29:24 +01:00
SDL_SetSurfaceBlendMode(graphics.menubuffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer = CREATE_SURFACE(320 + 16, 240 + 16);
2020-01-01 21:29:24 +01:00
SDL_SetSurfaceBlendMode(graphics.towerbuffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
SDL_SetSurfaceBlendMode(graphics.towerbuffer, SDL_BLENDMODE_NONE);
2020-01-01 21:29:24 +01:00
graphics.tempBuffer = CREATE_SURFACE(320, 240);
2020-01-01 21:29:24 +01:00
SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE);
#undef CREATE_SURFACE
if (game.skipfakeload)
game.gamestate = TITLEMODE;
if(game.usingmmmmmm==0) music.usingmmmmmm=false;
if(game.usingmmmmmm==1) music.usingmmmmmm=true;
2020-01-01 21:29:24 +01:00
if (game.slowdown == 0) game.slowdown = 30;
switch(game.slowdown){
case 30: game.gameframerate=34; break;
case 24: game.gameframerate=41; break;
case 18: game.gameframerate=55; break;
case 12: game.gameframerate=83; break;
default: game.gameframerate=34; break;
2020-01-01 21:29:24 +01:00
}
//Check to see if you've already unlocked some achievements here from before the update
if (game.swnbestrank > 0){
if(game.swnbestrank >= 1) NETWORK_unlockAchievement("vvvvvvsupgrav5");
if(game.swnbestrank >= 2) NETWORK_unlockAchievement("vvvvvvsupgrav10");
if(game.swnbestrank >= 3) NETWORK_unlockAchievement("vvvvvvsupgrav15");
if(game.swnbestrank >= 4) NETWORK_unlockAchievement("vvvvvvsupgrav20");
if(game.swnbestrank >= 5) NETWORK_unlockAchievement("vvvvvvsupgrav30");
if(game.swnbestrank >= 6) NETWORK_unlockAchievement("vvvvvvsupgrav60");
}
if(game.unlock[5]) NETWORK_unlockAchievement("vvvvvvgamecomplete");
if(game.unlock[19]) NETWORK_unlockAchievement("vvvvvvgamecompleteflip");
if(game.unlock[20]) NETWORK_unlockAchievement("vvvvvvmaster");
if (game.bestgamedeaths > -1) {
if (game.bestgamedeaths <= 500) {
NETWORK_unlockAchievement("vvvvvvcomplete500");
}
if (game.bestgamedeaths <= 250) {
NETWORK_unlockAchievement("vvvvvvcomplete250");
}
if (game.bestgamedeaths <= 100) {
NETWORK_unlockAchievement("vvvvvvcomplete100");
}
if (game.bestgamedeaths <= 50) {
NETWORK_unlockAchievement("vvvvvvcomplete50");
}
}
if(game.bestrank[0]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_station1_fixed");
if(game.bestrank[1]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_lab_fixed");
if(game.bestrank[2]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_tower_fixed");
if(game.bestrank[3]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_station2_fixed");
if(game.bestrank[4]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_warp_fixed");
if(game.bestrank[5]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_final_fixed");
2020-01-01 21:29:24 +01:00
obj.init();
#if !defined(NO_CUSTOM_LEVELS)
if (startinplaytest) {
game.levelpage = 0;
game.playcustomlevel = 0;
game.playassets = playassets;
ed.directoryList.clear();
ed.directoryList.push_back(playtestname);
LevelMetaData meta;
if (ed.getLevelMetaData(playtestname, meta)) {
ed.ListOfMetaData.clear();
ed.ListOfMetaData.push_back(meta);
} else {
ed.loadZips();
if (ed.getLevelMetaData(playtestname, meta)) {
ed.ListOfMetaData.clear();
ed.ListOfMetaData.push_back(meta);
} else {
printf("Level not found\n");
return 1;
}
}
game.loadcustomlevelstats();
game.customleveltitle=ed.ListOfMetaData[game.playcustomlevel].title;
game.customlevelfilename=ed.ListOfMetaData[game.playcustomlevel].filename;
if (savefileplaytest) {
game.playx = savex;
game.playy = savey;
game.playrx = saverx;
game.playry = savery;
game.playgc = savegc;
game.playmusic = savemusic;
game.cliplaytest = true;
script.startgamemode(23);
} else {
script.startgamemode(22);
}
graphics.fademode = 0;
}
#endif
2020-01-01 21:29:24 +01:00
key.isActive = true;
game.gametimer = 0;
2020-01-01 21:29:24 +01:00
while(!key.quitProgram)
{
f_time = SDL_GetTicks();
const Uint32 f_timetaken = f_time - f_timePrev;
if (!game.over30mode && f_timetaken < 34)
{
const volatile Uint32 f_delay = 34 - f_timetaken;
SDL_Delay(f_delay);
f_time = SDL_GetTicks();
}
f_timePrev = f_time;
timePrev = time_;
time_ = SDL_GetTicks();
deltaloop();
}
game.savestats();
NETWORK_shutdown();
SDL_Quit();
FILESYSTEM_deinit();
return 0;
}
void inline deltaloop()
{
//timestep limit to 30
const float rawdeltatime = static_cast<float>(time_ - timePrev);
accumulator += rawdeltatime;
2020-01-01 21:29:24 +01:00
Uint32 timesteplimit;
if (game.gamestate == EDITORMODE)
{
timesteplimit = 24;
}
else if (game.gamestate == GAMEMODE)
{
timesteplimit = game.gameframerate;
}
else
{
timesteplimit = 34;
}
while (accumulator >= timesteplimit)
{
accumulator = fmodf(accumulator, timesteplimit);
fixedloop();
}
const float alpha = game.over30mode ? static_cast<float>(accumulator) / timesteplimit : 1.0f;
graphics.alpha = alpha;
if (key.isActive)
{
switch (game.gamestate)
{
case PRELOADER:
preloaderrender();
break;
#if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR)
case EDITORMODE:
graphics.flipmode = false;
editorrender();
break;
#endif
case TITLEMODE:
titlerender();
break;
case GAMEMODE:
gamerender();
break;
case MAPMODE:
maprender();
break;
case TELEPORTERMODE:
teleporterrender();
break;
case GAMECOMPLETE:
gamecompleterender();
break;
case GAMECOMPLETE2:
gamecompleterender2();
break;
case CLICKTOSTART:
help.updateglow();
break;
}
gameScreen.FlipScreen();
}
}
void inline fixedloop()
{
// Update network per frame.
NETWORK_update();
key.Poll();
if(key.toggleFullscreen)
{
if(!gameScreen.isWindowed)
{
SDL_ShowCursor(SDL_DISABLE);
SDL_ShowCursor(SDL_ENABLE);
}
else
{
SDL_ShowCursor(SDL_ENABLE);
}
if(game.gamestate == EDITORMODE)
{
SDL_ShowCursor(SDL_ENABLE);
}
gameScreen.toggleFullScreen();
game.fullscreen = !game.fullscreen;
key.toggleFullscreen = false;
key.keymap.clear(); //we lost the input due to a new window.
if (game.glitchrunnermode)
{
game.press_left = false;
game.press_right = false;
game.press_action = true;
game.press_map = false;
}
}
if(!key.isActive)
{
Mix_Pause(-1);
Mix_PauseMusic();
if (!game.blackout)
{
FillRect(graphics.backBuffer, 0x00000000);
graphics.bprint(5, 110, "Game paused", 196 - help.glow, 255 - help.glow, 196 - help.glow, true);
graphics.bprint(5, 120, "[click to resume]", 196 - help.glow, 255 - help.glow, 196 - help.glow, true);
graphics.bprint(5, 220, "Press M to mute in game", 164 - help.glow, 196 - help.glow, 164 - help.glow, true);
graphics.bprint(5, 230, "Press N to mute music only", 164 - help.glow, 196 - help.glow, 164 - help.glow, true);
}
graphics.render();
gameScreen.FlipScreen();
//We are minimised, so lets put a bit of a delay to save CPU
SDL_Delay(100);
}
else
{
Mix_Resume(-1);
Mix_ResumeMusic();
game.gametimer++;
graphics.cutscenebarstimer();
switch(game.gamestate)
{
case PRELOADER:
preloaderlogic();
break;
#if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR)
case EDITORMODE:
//Input
editorinput();
////Logic
editorlogic();
break;
#endif
case TITLEMODE:
//Input
titleinput();
////Logic
titlelogic();
break;
case GAMEMODE:
// WARNING: If updating this code, don't forget to update Map.cpp mapclass::twoframedelayfix()
// Ugh, I hate this kludge variable but it's the only way to do it
if (script.dontrunnextframe)
{
script.dontrunnextframe = false;
}
else if (script.running)
{
script.run();
}
//Update old positions of entities - has to be done BEFORE gameinput!
for (size_t i = 0; i < obj.entities.size(); i++)
{
obj.entities[i].oldxp = obj.entities[i].xp;
obj.entities[i].oldyp = obj.entities[i].yp;
}
gameinput();
gamelogic();
break;
case MAPMODE:
mapinput();
maplogic();
break;
case TELEPORTERMODE:
if(game.useteleporter)
{
teleporterinput();
}
else
{
if (script.running)
{
script.run();
}
gameinput();
}
maplogic();
break;
case GAMECOMPLETE:
//Input
gamecompleteinput();
//Logic
gamecompletelogic();
break;
case GAMECOMPLETE2:
//Input
gamecompleteinput2();
//Logic
gamecompletelogic2();
break;
case CLICKTOSTART:
break;
default:
Fix frame-ordering backspacing empty line bug in script editor There is a long-standing bug with the script editor where if you delete the last character of a line, it IMMEDIATELY deletes the line you're on, and then moves your cursor back to the previous line. This is annoying, to say the least. The reason for this is that, in the sequence of events that happens in one frame (known as frame ordering), the code that backspaces one character from the line when you press Backspace is ran BEFORE the code to remove an empty line if you backspace it is ran. The former is located in key.Poll(), and the latter is located in editorinput(). Thus, when you press Backspace, the game first runs key.Poll(), sees that you've pressed Backspace, and dutifully removes the last character from a line. The line is now empty. Then, when the game gets around to the "Are you pressing Backspace on an empty line?" check in editorinput(), it thinks that you're pressing Backspace on an empty line, and then does the usual line-removing stuff. And actually, when it does the check in editorinput(), it ACTUALLY asks "Are you pressing Backspace on THIS frame and was the line empty LAST frame?" because it's checking against its own copy of the input buffer, before copying the input buffer to its own local copy. So the problem only happens if you press and hold Backspace for more than 1 frame. It's a small consolation prize for this annoyance, getting to tap-tap-tap Backspace in the hopes that you only press it for 1 frame, while in the middle of something more important to do like, oh I don't know, writing a script. So there are two potential solutions here: (1) Just change the frame ordering around. This is risky to say the least, because I'm not sure what behavior depends on exactly which frame order. It's not like it's key.Poll() and then IMMEDIATELY afterwards editorinput() is run, it's more like key.Poll(), some things that obviously depend on key.Poll() running before them, and THEN editorinput(). Also, editorinput() is only one possible thing that could be ran afterwards, on the next frame we could be running something else entirely instead. (2) Add a kludge variable to signal when the line is ALREADY empty so the game doesn't re-check the already-empty line and conclude that you're already immediately backspacing an empty line. I went with (2) for this commit, and I've added the kludge variable key.linealreadyemptykludge. However, that by itself isn't enough to fix it. It only adds about a frame or so of delay before the game goes right back to saying "Oh, you're ALREADY somehow pressing backspace again? I'll just delete this line real quick" and the behavior is basically the same as before, except now you have to hit Backspace for TWO frames or less instead of one in order to not have it happen. What we need is to have a delay set as well, when the game deletes the last line of a char. So I set ed.keydelay to 6 as well if editorinput() sses that key.linealreadyemptykludge is on.
2020-01-19 03:17:46 +01:00
break;
2020-01-01 21:29:24 +01:00
}
}
//Screen effects timers
if (key.isActive && game.flashlight > 0)
{
game.flashlight--;
}
if (key.isActive && game.screenshake > 0)
{
game.screenshake--;
graphics.updatescreenshake();
}
if (graphics.screenbuffer->badSignalEffect)
{
UpdateFilter();
}
//We did editorinput, now it's safe to turn this off
key.linealreadyemptykludge = false;
if (game.savemystats)
{
game.savemystats = false;
game.savestats();
}
//Mute button
#if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR)
bool inEditor = ed.textentry || ed.scripthelppage == 1;
#else
bool inEditor = false;
#endif
if (key.isDown(KEYBOARD_m) && game.mutebutton<=0 && !inEditor)
{
game.mutebutton = 8;
if (game.muted)
{
game.muted = false;
}
else
{
game.muted = true;
}
}
if(game.mutebutton>0)
{
game.mutebutton--;
}
2020-01-01 21:29:24 +01:00
if (key.isDown(KEYBOARD_n) && game.musicmutebutton <= 0 && !inEditor)
{
game.musicmutebutton = 8;
game.musicmuted = !game.musicmuted;
}
if (game.musicmutebutton > 0)
{
game.musicmutebutton--;
}
if (game.muted)
{
Mix_VolumeMusic(0) ;
Mix_Volume(-1,0);
}
else
{
Mix_Volume(-1,MIX_MAX_VOLUME);
if (game.musicmuted || game.completestop)
{
Mix_VolumeMusic(0);
}
else
{
Mix_VolumeMusic(MIX_MAX_VOLUME);
}
}
if (key.resetWindow)
{
key.resetWindow = false;
gameScreen.ResizeScreen(-1, -1);
}
music.processmusic();
graphics.processfade();
game.gameclock();
2020-01-01 21:29:24 +01:00
}