This commit is contained in:
Tim Felgentreff 2022-07-26 17:58:20 +02:00
commit c2b0dcf7ba
7 changed files with 71 additions and 59 deletions

View file

@ -181,10 +181,6 @@ static bool FindNearestReachableTerrainType(int movemask, int resmask, int range
order->CurrentResource = harvester.CurrentResource;
order->DoneHarvesting = true;
if (harvester.CurrentResource) {
const ResourceInfo &resinfo = *harvester.Type->ResInfo[harvester.CurrentResource];
}
if (depot == NULL) {
depot = FindDeposit(harvester, 1000, harvester.CurrentResource);
}

View file

@ -836,6 +836,7 @@ static int CclLoadTileModels(lua_State *l)
*/
static int CclDefineTileset(lua_State *l)
{
Map.Create();
Map.Tileset->parse(l);
// Load and prepare the tileset

View file

@ -405,8 +405,8 @@ void Exit(int err)
FreeButtonStyles();
FreeAllContainers();
freeGuichan();
DebugPrint("Frames %lu, Slow frames %d = %ld%%\n" _C_
FrameCounter _C_ SlowFrameCounter _C_
fprintf(stdout, "Frames %lu, Slow frames %d = %ld%%\n",
FrameCounter, SlowFrameCounter,
(SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1));
lua_settop(Lua, 0);
lua_close(Lua);

View file

@ -553,21 +553,26 @@ void CUnit::Release(bool final)
// removed, but fog of war calculations are still underway, where we want to
// read a BoolFlag; there are more instances of this...)
for (std::vector<COrder *>::iterator order = Orders.begin(); order != Orders.end(); ++order) {
delete *order;
COrder *orderToDelete = *order;
*order = NULL;
delete orderToDelete;
}
Orders.clear();
if (SavedOrder != NULL) {
delete SavedOrder;
COrder *order = SavedOrder;
SavedOrder = NULL;
delete order;
}
if (NewOrder != NULL) {
delete NewOrder;
COrder *order = NewOrder;
NewOrder = NULL;
delete order;
}
if (CriticalOrder != NULL) {
delete CriticalOrder;
COrder *order = CriticalOrder;
CriticalOrder = NULL;
delete order;
}
// Remove the unit from the global units table.
@ -1092,11 +1097,12 @@ void CUnit::AddInContainer(CUnit &host)
NextContained = PrevContained = this;
host.UnitInside = this;
} else {
// keep sorted by size
int mySize = Type->BoardSize;
// keep sorted by size.
// FIXME: if we're loading a game, the Type may not have been initialized yet!!
int mySize = Type ? Type->BoardSize : 1;
NextContained = host.UnitInside;
bool becomeFirst = true;
while (NextContained->Type->BoardSize > mySize) {
while (NextContained->Type ? NextContained->Type->BoardSize : 1 > mySize) {
becomeFirst = false;
NextContained = NextContained->NextContained;
if (NextContained == host.UnitInside) {

View file

@ -720,6 +720,7 @@ const EventCallback *GetCallbacks()
}
static int SkipFrameMask = 0;
static unsigned long NextSlowFrameReaction = FRAMES_PER_SECOND * 10;
/**
** Wait for interactive input event for one frame.
@ -740,26 +741,22 @@ void WaitEventsOneFrame()
Uint32 ticks = SDL_GetTicks();
if (ticks > NextFrameTicks) { // We are too slow :(
++SlowFrameCounter;
if (SlowFrameCounter > FRAMES_PER_SECOND) {
if (SlowFrameCounter > NextSlowFrameReaction) {
unsigned long pct = (SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1);
bool warn = false;
if (pct >= 40) {
warn = (SkipFrameMask < 0b101);
if (pct >= 60) {
SkipFrameMask = 0b111;
} else if (pct >= 40) {
SkipFrameMask = 0b101;
} else if (pct >= 20) {
warn = (SkipFrameMask < 0b11);
SkipFrameMask = 0b11;
} else if (pct >= 10) {
warn = (SkipFrameMask < 0b1);
SkipFrameMask = 0b1;
}
if (warn) {
fprintf(stdout, "WARNING WARNING WARNING\n"
"Frames %lu, Slow frames %d = %lu%%, starting to render only every %d%s frame.\n",
FrameCounter, SlowFrameCounter, pct, SkipFrameMask + 1, SkipFrameMask == 1 ? "nd" : "th");
fflush(stdout);
SlowFrameCounter = 0;
}
NextSlowFrameReaction += FRAMES_PER_SECOND * 10;
fprintf(stdout, "WARNING WARNING WARNING\n"
"Frames %lu, Slow frames %d = %lu%%, starting to render only every %d%s frame.\n",
FrameCounter, SlowFrameCounter, pct, SkipFrameMask + 1, SkipFrameMask == 1 ? "nd" : "th");
fflush(stdout);
}
}
@ -820,6 +817,38 @@ void WaitEventsOneFrame()
static Uint32 LastTick = 0;
static int RefreshRate = 0;
static void RenderBenchmarkOverlay()
{
if (!RefreshRate) {
int displayCount = SDL_GetNumVideoDisplays();
SDL_DisplayMode mode;
for (int i = 0; i < displayCount; i++) {
SDL_GetDesktopDisplayMode(0, &mode);
if (mode.refresh_rate > RefreshRate) {
RefreshRate = mode.refresh_rate;
}
}
}
// show a bar representing fps, where the entire bar is the max refresh rate of attached displays
Uint32 nextTick = SDL_GetTicks();
Uint32 frameTime = nextTick - LastTick;
int fps = std::min(RefreshRate, static_cast<int>(frameTime > 0 ? (1000.0 / frameTime) : 0));
LastTick = nextTick;
// draw the full bar
SDL_SetRenderDrawColor(TheRenderer, 255, 0, 0, 255);
SDL_Rect frame = { Video.Width - 10, 2, 8, RefreshRate };
SDL_RenderDrawRect(TheRenderer, &frame);
// draw the inner fps gage
SDL_SetRenderDrawColor(TheRenderer, 0, 255, 0, 255);
SDL_Rect bar = { Video.Width - 8, 2 + RefreshRate - fps, 4, fps };
SDL_RenderFillRect(TheRenderer, &bar);
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255);
}
void RealizeVideoMemory()
{
++FrameCounter;
@ -839,34 +868,7 @@ void RealizeVideoMemory()
SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
}
if (Parameters::Instance.benchmark) {
if (!RefreshRate) {
int displayCount = SDL_GetNumVideoDisplays();
SDL_DisplayMode mode;
for (int i = 0; i < displayCount; i++) {
SDL_GetDesktopDisplayMode(0, &mode);
if (mode.refresh_rate > RefreshRate) {
RefreshRate = mode.refresh_rate;
}
}
}
// show a bar representing fps, where the entire bar is the max refresh rate of attached displays
Uint32 nextTick = SDL_GetTicks();
Uint32 frameTime = nextTick - LastTick;
int fps = std::min(RefreshRate, static_cast<int>(frameTime > 0 ? (1000.0 / frameTime) : 0));
LastTick = nextTick;
// draw the full bar
SDL_SetRenderDrawColor(TheRenderer, 255, 0, 0, 255);
SDL_Rect frame = { Video.Width - 10, 2, 8, RefreshRate };
SDL_RenderDrawRect(TheRenderer, &frame);
// draw the inner fps gage
SDL_SetRenderDrawColor(TheRenderer, 0, 255, 0, 255);
SDL_Rect bar = { Video.Width - 8, 2 + RefreshRate - fps, 4, fps };
SDL_RenderFillRect(TheRenderer, &bar);
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255);
RenderBenchmarkOverlay();
}
SDL_RenderPresent(TheRenderer);
NumRects = 0;

View file

@ -271,11 +271,17 @@ static GLfloat modelview[4 * 4];
static GLfloat projection[4 * 4];
static GLfloat matrix[4 * 4] = {0.0f};
static bool RenderWithShaderInternal(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer);
// keep this function small, so the compiler can inline it
bool RenderWithShader(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer) {
if (!canUseShaders || currentShaderIdx == 0) {
return false;
}
return RenderWithShaderInternal(renderer, win, backBuffer);
}
static bool RenderWithShaderInternal(SDL_Renderer *renderer, SDL_Window* win, SDL_Texture* backBuffer) {
GLint oldProgramId;
// Detach the texture
SDL_SetRenderTarget(renderer, NULL);

View file

@ -39,7 +39,7 @@ int main(int argc, char * argv[]) {
FILE * file;
int old_ver[4] = { -1, -1, -1, -1 };
int new_ver[4] = { -1, -1, -1, -1 };
char* old_rev = (char*)calloc(sizeof(char), 1024);
char old_rev[1024] {};
if ( argc != 3 )
return 1;
@ -62,11 +62,12 @@ int main(int argc, char * argv[]) {
}
file = fopen(".git/HEAD", "r");
char git_rev_buf[1024] {};
char *git_rev, *gitrevfile;
if ( file ) {
git_rev = (char*)calloc(sizeof(char), 1024);
git_rev = git_rev_buf;
if (fscanf(file, "ref: %s", git_rev) != 1 ) {
int ignored = fscanf(file, "%s", git_rev);
fscanf(file, "%s", git_rev);
}
fclose(file);
gitrevfile = (char*)calloc(sizeof(char), strlen(git_rev) + 6);
@ -74,8 +75,8 @@ int main(int argc, char * argv[]) {
file = fopen(gitrevfile, "r");
free(gitrevfile);
if (file) {
git_rev = (char*)calloc(sizeof(char), 1024);
int ignored = fscanf(file, "%s", git_rev);
git_rev = git_rev_buf;
fscanf(file, "%s", git_rev);
fclose(file);
}
} else {