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
3 changes: 3 additions & 0 deletions gameconfig.lua.default
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ Server = {
Visual = {
ChunkNormalSmoothAngle = 0.0
}
Graphics = {
FPSLimit = -1
}
1 change: 1 addition & 0 deletions include/ClientLib/BlockSelectionBar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace tsom

void SelectNext();
void SelectPrevious();
void SelectPickedBlock(tsom::BlockIndex pickedBlockIndex);

BlockSelectionBar& operator=(const BlockSelectionBar&) = delete;
BlockSelectionBar& operator=(BlockSelectionBar&&) = delete;
Expand Down
15 changes: 15 additions & 0 deletions src/ClientLib/BlockSelectionBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ namespace tsom
m_selectedBlockIndex = m_blockLibrary.GetBlockIndex(s_selectableBlocks[m_selectedIndex]);
}

void BlockSelectionBar::SelectPickedBlock(tsom::BlockIndex pickedBlockIndex)
{
if (!m_blockLibrary.IsValidBlock(pickedBlockIndex))
return;

auto it = std::find(s_selectableBlocks.begin(), s_selectableBlocks.end(), m_blockLibrary.GetBlockData(pickedBlockIndex).name);
if (it == s_selectableBlocks.end())
return;

m_inventorySprites[m_selectedIndex]->SetColor(Nz::Color::sRGBToLinear(Nz::Color::Gray()));
m_selectedIndex = std::distance(s_selectableBlocks.begin(), it);
m_inventorySprites[m_selectedIndex]->SetColor(Nz::Color::White());
m_selectedBlockIndex = pickedBlockIndex;
}

void BlockSelectionBar::Layout()
{
BaseWidget::Layout();
Expand Down
13 changes: 8 additions & 5 deletions src/CommonLib/Scripting/ScriptingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace tsom

case LUA_TNUMBER:
if (lua_isinteger(L, idx))
lua_pushfstring(L, LUA_INTEGER_FMT, (LUAI_UACINT)lua_tointeger(L, idx));
lua_pushstring(L, std::to_string(lua_tointeger(L, idx)).c_str());
else
lua_pushfstring(L, LUA_NUMBER_FMT, (LUAI_UACNUMBER)lua_tonumber(L, idx));
break;
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace tsom
default:
{
int tt = luaL_getmetafield(L, idx, "__name");
const char* name = (tt == LUA_TSTRING) ? lua_tostring(L, idx) : lua_typename(L, t);
const char* name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t);
lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx));
if (tt != LUA_TNIL)
lua_replace(L, -2);
Expand Down Expand Up @@ -121,7 +121,9 @@ namespace tsom
{
lua_pushvalue(L, -1);
lua_gettable(L, visitedIndex);
if (lua_isnil(L, -1))
bool is_not_visited = lua_isnil(L, -1);
lua_pop(L, 1);
if (is_not_visited)
{
lua_pop(L, 1);

Expand Down Expand Up @@ -166,7 +168,7 @@ namespace tsom

lua_pop(L, 2); // pop new indentation and visited table

luaL_addvalue(&b); //< add (and pop) new indentation to the buffer
luaL_addvalue(&b); //< add (and pop) old indentation to the buffer

lua_pushstring(L, "}");
luaL_addvalue(&b);
Expand Down Expand Up @@ -202,9 +204,10 @@ namespace tsom

std::size_t length;
const char* str = lua_tolstring(L, -1, &length);
oss << std::string(str, length);
lua_pop(L, 1);
if (!first)
oss << "\t";
oss << std::string(str, length);

first = false;
}
Expand Down
1 change: 1 addition & 0 deletions src/CommonLib/Utility/CrashHandlerWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Nazara/Core/Error.hpp>
#include <cpptrace/cpptrace.hpp>
#include <fmt/core.h>
#include <fmt/format.h>
#include <array>
#include <cstring>
#include <cstdio>
Expand Down
16 changes: 16 additions & 0 deletions src/Game/GameAppComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <CommonLib/Systems/PlanetSystem.hpp>
#include <CommonLib/Systems/ShipSystem.hpp>
#include <Game/GameConfigAppComponent.hpp>
#include <Game/GameConfigs.hpp>
#include <Game/States/BackgroundState.hpp>
#include <Game/States/ConnectionState.hpp>
#include <Game/States/DebugInfoState.hpp>
Expand Down Expand Up @@ -160,6 +161,8 @@ namespace tsom
stateData->swapchain = &swapchain;
stateData->world = &world;

m_fpsLimit = stateData->config->GetIntegerValue<Nz::Int16>(Config::Graphics_FPSLimit);

#ifdef TSOM_DEV_TOOLS
stateData->imgui = &m_imguiRuntime.value();
#endif
Expand Down Expand Up @@ -209,6 +212,19 @@ namespace tsom
if (m_imguiRuntime)
m_imguiRuntime->EndFrame();
#endif

// FPS limiting
if (m_fpsLimit > 0)
{
Nz::Time targetDuration = Nz::Time::Seconds(1.f / m_fpsLimit);
Nz::Time elapsed = m_frameClock.GetElapsedTime();
if (elapsed < targetDuration)
{
Nz::Time sleepTime = targetDuration - elapsed;
std::this_thread::sleep_for(std::chrono::microseconds(sleepTime.AsMicroseconds()));
}
}
m_frameClock.Restart();
}

bool GameAppComponent::CheckAssets()
Expand Down
4 changes: 4 additions & 0 deletions src/Game/GameAppComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <ClientLib/ClientBlockLibrary.hpp>
#include <CommonLib/Systems/GravityPhysicsSystem.hpp>
#include <Nazara/Core/ApplicationComponent.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/StateMachine.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <Nazara/Widgets/Canvas.hpp>
Expand Down Expand Up @@ -62,6 +63,9 @@ namespace tsom
std::optional<ImGuiRuntime> m_imguiRuntime;
#endif
Nz::StateMachine m_stateMachine;

Nz::HighPrecisionClock m_frameClock;
Nz::Int16 m_fpsLimit;
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/Game/GameConfigAppComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace tsom

return Nz::Ok(shadowMapSize);
});

RegisterIntegerOption(Config::Graphics_FPSLimit, -1, 1000, -1);
}

std::filesystem::path GameConfigFile::GetPath()
Expand Down
1 change: 1 addition & 0 deletions src/Game/GameConfigs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace tsom::Config
static constexpr auto Input_MouseSensitivity = ConfigFile::FloatOptionName{ "Input.MouseSensitivity" };
static constexpr auto Player_Token = ConfigFile::StringOptionName{ "Player.Token" };
static constexpr auto Server_Port = ConfigFile::IntegerOptionName{ "Server.Port" };
static constexpr auto Graphics_FPSLimit = ConfigFile::IntegerOptionName{ "Graphics.FPSLimit" };
}

#endif // TSOM_GAME_GAMECONFIGS_HPP
11 changes: 7 additions & 4 deletions src/Game/States/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,6 @@ namespace tsom
if (!m_isMouseLocked)
return;

if (event.button != Nz::Mouse::Left && event.button != Nz::Mouse::Right)
return;

auto& stateData = GetStateData();

if (!m_pilotedShip)
Expand Down Expand Up @@ -749,7 +746,7 @@ namespace tsom

stateData.networkSession->SendPacket(mineBlock);
}
else
else if (event.button == Nz::Mouse::Right)
{
BlockIndices blockIndices = chunkContainer.GetBlockIndices(hitChunk.GetIndices(), hitCoordinates->blockIndices);

Expand All @@ -772,6 +769,12 @@ namespace tsom

stateData.networkSession->SendPacket(placeBlock);
}
else
{
// Pick block
tsom::BlockIndex pickedBlockIndex = chunkComponent->chunk.Get()->GetBlockContent(hitCoordinates->blockIndices);
m_blockSelectionBar->SelectPickedBlock(pickedBlockIndex);
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/ServerLib/Scripting/ServerScriptingLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <CommonLib/CharacterController.hpp>
#include <CommonLib/Components/ClassInstanceComponent.hpp>
#include <CommonLib/Scripting/ScriptingUtils.hpp>
#include <CommonLib/Planet.hpp>
#include <ServerLib/ServerAtmosphere.hpp>
#include <ServerLib/ServerInstance.hpp>
#include <ServerLib/ServerPlanetEnvironment.hpp>
Expand Down Expand Up @@ -137,7 +138,8 @@ namespace tsom
// TODO: Build properties from Lua table
return std::make_unique<ServerPlanetEnvironment>(m_serverInstance, databaseId, std::move(generatorName), chunkCount, type, std::vector<EntityProperty>{});
}),
"GetDatabaseId", LuaFunction(&ServerPlanetEnvironment::GetDatabaseId)
"GetDatabaseId", LuaFunction(&ServerPlanetEnvironment::GetDatabaseId),
"GetChunkContainer", LuaFunction([](ServerPlanetEnvironment& env) -> ChunkContainer* { return &env.GetPlanet(); })
);

state.new_usertype<ServerShipEnvironment>("ShipEnvironment",
Expand Down
56 changes: 56 additions & 0 deletions src/ServerLib/Session/PlayerSessionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,31 @@ namespace tsom
m_player->UpdateRootEnvironment(env);
m_player->Respawn(env, spawnPos, Nz::Quaternionf::Identity());
}
else if (message.starts_with("/tpplayer ") && m_player->HasPermission(PlayerPermission::Admin))
{
constexpr std::size_t commandLength = sizeof("/tpplayer ") - 1;

std::string targetName(&message[commandLength], message.size() - commandLength);
ServerPlayer* targetPlayer = m_player->GetServerInstance().FindPlayerByNickname(targetName);
if (!targetPlayer)
{
m_player->SendChatMessage("player not found");
return;
}

entt::handle targetEntity = targetPlayer->GetControlledEntityReference();
if (!targetEntity)
{
m_player->SendChatMessage("target player has no controlled entity");
return;
}

Nz::Vector3f targetPos = targetEntity.get<Nz::NodeComponent>().GetPosition();
ServerEnvironment* targetEnvironment = ServerEnvironment::GetEnvironment(targetEntity);
m_player->Respawn(targetEnvironment, targetPos + Nz::Vector3f::Up() * 2.f, Nz::Quaternionf::Identity());

return;
}
else if (message == "/fly")
{
entt::handle playerEntity = m_player->GetControlledEntityReference();
Expand Down Expand Up @@ -724,6 +749,37 @@ namespace tsom
{
throw std::runtime_error("test exception");
}
else if (message == "/links")
{
m_player->SendChatMessage("--- Game ressources ---");
m_player->SendChatMessage("Join our community on Discord : http://discord.gg/2WUU6Sp");
m_player->SendChatMessage("Check out the wiki : https://tsom.fandom.com/fr");
m_player->SendChatMessage("To suggest a new feature or an idea : https://tsom-idea.digitalpulse.software");
m_player->SendChatMessage("To report an issue : https://github.com/DigitalPulseSoftware/ThisSpaceOfMine/issues");
return;
}
else if (message == "/help") {
m_player->SendChatMessage("--- Available commands ---");
m_player->SendChatMessage("/help - Show this help message");
m_player->SendChatMessage("/links - Show game resources");
m_player->SendChatMessage("/respawn - Respawn at the default spawnpoint");
m_player->SendChatMessage("/tpplanet <planet_id> - Teleport to the specified planet");
m_player->SendChatMessage("/fly - Toggle flying mode");
m_player->SendChatMessage("/spawnship [slot] - Spawn your ship from the specified slot (default: 0). Slot must be in [0;3[");
m_player->SendChatMessage("/spawncomputer - Spawn a computer where you're looking at");
m_player->SendChatMessage("/spawnsensor - Spawn an atmosphere sensor where you're looking at");
if (m_player->HasPermission(PlayerPermission::Admin))
{
m_player->SendChatMessage("/tpplayer <player_name> - Teleport to the specified player");
m_player->SendChatMessage("/regenchunk - Regenerate the chunk you're currently in");
m_player->SendChatMessage("/spawntree - Spawn a tree where you're looking at");
m_player->SendChatMessage("/removetree - Remove a tree where you're looking at");
m_player->SendChatMessage("/spawnplatform - Spawn a platform at your position (deprecated)");
m_player->SendChatMessage("/crashserver - Crash the server (for testing purposes)");
m_player->SendChatMessage("/crashserver 1 - Throw an exception on the server (for testing purposes)");
}
return;
}

m_player->GetServerInstance().BroadcastChatMessage(std::move(playerChat.message), m_player->GetPlayerIndex());
}
Expand Down
Loading