Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Strife.ML
Submodule Strife.ML updated 1 files
+2 −2 CMakeLists.txt
15 changes: 12 additions & 3 deletions src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extern ConsoleVar<bool> g_developerMode("developer-mode", true, true);
#endif

ConsoleVar<bool> g_isServer("server", false);
extern ConsoleVar<bool> g_fastUpdate("fast-update", false);
extern ConsoleVar<float> g_trainDeltaTime("train-dt", 1 / 60.f, true);

static ConcurrentQueue<std::function<void()>> g_workQueue;

Expand Down Expand Up @@ -193,11 +195,18 @@ void Engine::RunFrame()

float now = GetTimeSeconds();
float timeUntilUpdate = nextGameToRun->nextUpdateTime - now;

if (!g_fastUpdate.Value() && timeUntilUpdate > 0)
{
AccurateSleepFor(timeUntilUpdate);
}
else
{
nextGameToRun->nextUpdateTime = now;
}

AccurateSleepFor(timeUntilUpdate);
nextGameToRun->RunFrame(GetTimeSeconds());
nextGameToRun->RunFrame(GetTimeSeconds());
nextGameToRun->nextUpdateTime = nextGameToRun->nextUpdateTime + 1.0f / nextGameToRun->targetTickRate;

ScriptCompiler::GetInstance()->Update();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ class Engine
std::function<void()> _loadResources;
};

extern ConsoleVar<bool> g_developerMode;
extern ConsoleVar<bool> g_developerMode;
extern ConsoleVar<bool> g_fastUpdate;
extern ConsoleVar<float> g_trainDeltaTime;
79 changes: 50 additions & 29 deletions src/Net/ServerGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ void BaseGameInstance::RunFrame(float currentTime)
auto input = engine->GetInput();
auto sdlManager = engine->GetSdlManager();

if (!isHeadless)
const bool fastUpdate = g_fastUpdate.Value();
const float trainDt = g_trainDeltaTime.Value();

if (!isHeadless && !fastUpdate)
{
input->Update();
sdlManager->Update();
Expand All @@ -41,17 +44,26 @@ void BaseGameInstance::RunFrame(float currentTime)
{
scene->lastFrameStart = currentTime;
scene->isFirstFrame = false;
lastRenderTime = currentFrameStart;
}

auto realDeltaTime = currentTime - scene->lastFrameStart;
float renderDeltaTime;

float renderDeltaTime = !engine->IsPaused()
? realDeltaTime
: realDeltaTime; //0;
if (fastUpdate)
{
renderDeltaTime = trainDt;
}
else
{
renderDeltaTime = !engine->IsPaused()
? realDeltaTime
: realDeltaTime; //0;
}

scene->deltaTime = renderDeltaTime;

if (!isHeadless)
if (!isHeadless && !fastUpdate)
{
engine->GetSoundManager()->UpdateActiveSoundEmitters(scene->deltaTime);
}
Expand All @@ -70,34 +82,20 @@ void BaseGameInstance::RunFrame(float currentTime)
bool allowConsole = !isHeadless && g_developerMode.Value();
auto console = engine->GetConsole();

if (allowConsole)
{
if (console->IsOpen())
{
console->HandleInput(input);
}

bool tildePressed = InputButton(SDL_SCANCODE_GRAVE).IsPressed();
std::chrono::duration<float> timeSinceLastRender = std::chrono::duration_cast<std::chrono::duration<float>>(currentFrameStart - lastRenderTime);

if (tildePressed)
if (!isHeadless && (!fastUpdate || (timeSinceLastRender.count() >= trainDt)))
{
if (fastUpdate)
{
if (console->IsOpen())
{
console->Close();
engine->ResumeGame();
}
else
{
console->Open();
engine->PauseGame();
}
input->Update();
sdlManager->Update();
}
}

if (!isHeadless)
{
Render(scene.get(), realDeltaTime, renderDeltaTime);
lastRenderTime = currentFrameStart;

if (!fastUpdate)
{
static int count = 0;

Expand All @@ -112,6 +110,30 @@ void BaseGameInstance::RunFrame(float currentTime)
}

input->GetMouse()->SetMouseScale(Vector2::Unit() * scene->GetCamera()->Zoom());

if (allowConsole)
{
if (console->IsOpen())
{
console->HandleInput(input);
}

bool tildePressed = InputButton(SDL_SCANCODE_GRAVE).IsPressed();

if (tildePressed)
{
if (console->IsOpen())
{
console->Close();
engine->ResumeGame();
}
else
{
console->Open();
engine->PauseGame();
}
}
}
}

scene->lastFrameStart = currentTime;
Expand All @@ -126,7 +148,7 @@ void BaseGameInstance::RunFrame(float currentTime)
}

void BaseGameInstance::Render(Scene* scene, float deltaTime, float renderDeltaTime)
{
{
auto input = engine->GetInput();
auto sdlManager = engine->GetSdlManager();
auto renderer = engine->GetRenderer();
Expand Down Expand Up @@ -211,7 +233,6 @@ BaseGameInstance::BaseGameInstance(Engine* engine, SLNet::RakPeerInterface* rakn
engine(engine),
fileTransferService(&rpcManager)
{

}

void ServerGame::HandleNewConnection(SLNet::Packet* packet)
Expand Down
2 changes: 2 additions & 0 deletions src/Net/ServerGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ struct BaseGameInstance
float targetTickRate;
float nextUpdateTime = 0;
FileTransferService fileTransferService;

std::chrono::steady_clock::time_point lastRenderTime;
};

struct ServerGame : BaseGameInstance
Expand Down
7 changes: 4 additions & 3 deletions src/Renderer/SdlManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ void SdlManager::Init()
fwprintf(stderr, L"SetProcessDpiAwareness: %hs\n", err.ErrorMessage());
}
#endif

if (SDL_Init(SDL_INIT_EVERYTHING) < 0)

unsigned int flags = SDL_INIT_EVENTS | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER;
if (SDL_Init(flags) < 0)
{
FatalError("Failed to initialize SDL");
FatalError("Failed to initialize SDL: %s", SDL_GetError());
}

SetDefaultValuesOnFirstRun();
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void ResourceManager::LoadContentFile(const char* filePath)

ResourceSettings settings;
settings.resourceName = name.c_str();
settings.path = path.c_str();
settings.path = path.string().c_str();
settings.resourceType = type.c_str();
settings.attributes = attributes;

Expand Down
2 changes: 1 addition & 1 deletion src/Scene/EntitySerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ std::string SerializeEntityProperty(const bool& value)
template<>
bool DeserializeEntityProperty(const std::string& value)
{
if (value == "true" || value != "0")
if (value == "true" || value == "1")
{
return true;
}
Expand Down
24 changes: 14 additions & 10 deletions src/Scene/IGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ void IGame::Run()

void IGame::Render(PipelineRunner& renderPipeline)
{
renderPipeline
.ModifyRendererState([](RendererState& state)
{
state.SetDepthBufferEnabled(true);
state.ClearBuffers();
})
.UseSceneCamera()
.RenderEntities()
.RenderDebugPrimitives()
.RenderImgui();
renderPipeline.ModifyRendererState([](RendererState& state)
{
state.SetDepthBufferEnabled(true);
state.ClearBuffers();
});

if (!(g_fastUpdate.Value()))
{
renderPipeline
.UseSceneCamera()
.RenderEntities()
.RenderDebugPrimitives()
.RenderImgui();
}

renderPipeline
.UseUiCamera()
Expand Down
3 changes: 2 additions & 1 deletion src/Scene/SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ void SceneManager::BuildNewScene(const SceneModel* sceneModel)
}
else
{
_scene->CreateEntity(entity.type, serializer);
Entity* createdEntity = _scene->CreateEntity(entity.type, serializer);
createdEntity->name = StringId(entity.name);
}
}

Expand Down