Skip to content

Commit

Permalink
The client can now somewhat connect to the server
Browse files Browse the repository at this point in the history
There are a lot of errors but now the client stays connected to the
server without crashing or disconnecting after a few seconds
  • Loading branch information
hhyyrylainen committed Dec 8, 2018
1 parent 27fc287 commit 8b6bb4f
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 278 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assets/*
/src/thrive_version.h
/src/main.cpp
/src/generated
/src/server/main.cpp

# asset symlinks
/Fonts
Expand Down
2 changes: 1 addition & 1 deletion SetupThrive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def parseExtraArgs
leviathan = Leviathan.new(
# Use this if you always want the latest commit
# version: "develop",
version: "5f3f3d1b3ef74b27f3ae7e1fb5f32a740dfcd813",
version: "e41a1b489733462337fd8fb914859c38d8bb9051",
# Doesn't actually work, but leviathan doesn't install with sudo by
# default, or install at all for that matter
noInstallSudo: true
Expand Down
29 changes: 24 additions & 5 deletions scripts/gui/main_menu.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,47 @@ export function runMenuSetup(){
}, true);
document.getElementById("extrasButton").addEventListener("click", (event) => {
event.stopPropagation();
common.playButtonPressSound();
$("#mainMenu").slideUp("fast", () => {
$("#extrasMenu").slideDown("fast");
});
}, true);
document.getElementById("backFromExtras").addEventListener("click", (event) => {
event.stopPropagation();
common.playButtonPressSound();
$("#extrasMenu").slideUp("fast", () => {
$("#mainMenu").slideDown("fast");
});
}, true);
document.getElementById("toMultiplayerProtoButton").addEventListener("click", (event) => {
event.stopPropagation();
common.playButtonPressSound();
$("#extrasMenu").slideUp("fast", () => {
$("#serverConnectingMenu").slideDown("fast");
});
}, true);
document.getElementById("backFromConnecting").addEventListener("click", (event) => {
event.stopPropagation();
common.playButtonPressSound();
$("#serverConnectingMenu").slideUp("fast", () => {
$("#extrasMenu").slideDown("fast");
});
}, true);
document.getElementById("backFromConnecting").addEventListener("click", (event) => {
event.stopPropagation();
common.playButtonPressSound();
$("#serverConnectingMenu").slideUp("fast", () => {
$("#extrasMenu").slideDown("fast");
});
}, true);
document.getElementById("connectToServerButton").addEventListener("click", (event) => {
event.stopPropagation();
common.playButtonPressSound();
connectToSelectedServerURL();
}, true);
document.getElementById("disconnectFromServer").addEventListener("click", (event) => {
event.stopPropagation();
common.playButtonPressSound();
disconnectFromCurrentServer();
}, true);

Expand Down Expand Up @@ -89,6 +96,10 @@ export function runMenuSetup(){
doExitToMenu();
});

Leviathan.OnGeneric("MicrobeStageEnteredClient", () => {
switchToMicrobeHUD();
});

// Server status message display
Leviathan.OnGeneric("ConnectStatusMessage", (event, vars) => {
handleConnectionStatusEvent(vars);
Expand Down Expand Up @@ -223,6 +234,8 @@ function disconnectFromCurrentServer(){

handleConnectionStatusEvent({show: false});
}

// ThriveGame handles moving back to the menu GUI
}

function handleConnectionStatusEvent(event){
Expand All @@ -244,11 +257,6 @@ function onMicrobeIntroEnded(error){

menuAlreadySkipped = true;

if(jams){

jams.Pause();
}

if(common.isInEngine()){

// Make sure no video is playing in case we did an immediate start
Expand All @@ -261,6 +269,17 @@ function onMicrobeIntroEnded(error){
// Show the microbe GUI anyway for testing purposes
}

switchToMicrobeHUD();
}

function switchToMicrobeHUD(){

// Stop menu music
if(jams){

jams.Pause();
}

// Hide main menu
// If this is ever restored this needs to be set to "flex"
document.getElementById("topLevelMenuContainer").style.display = "none";
Expand Down
24 changes: 12 additions & 12 deletions scripts/gui/thrive_gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@
<div class="MenuButton" id="backFromConnecting">Back</div>
</div>

<!-- Server connection info dialog -->
<div id="serverConnectPopup" class="Overlay" style="display: none;">
<div class="MenuDialogBox">
<div class="Centered">Connecting to <span id="currentServerAddress">unknown</span>
</div>
<hr style="width: 80%; margin-bottom: 15px;">
<div id="currentConnectionStatusMessage">Connection hasn't started</div>
<div class="MenuButton" style="margin-top: auto;" id="disconnectFromServer">
Disconnect</div>
</div>
</div>

<span id="versionNumber" style="position: absolute; right: 0; bottom: 0;">
JavaScript not loaded...
</span>
</div>

<!-- Server connection info dialog -->
<div id="serverConnectPopup" class="Overlay" style="display: none;">
<div class="MenuDialogBox">
<div class="Centered">Connecting to <span id="currentServerAddress">unknown</span>
</div>
<hr style="width: 80%; margin-bottom: 15px;">
<div id="currentConnectionStatusMessage">Connection hasn't started</div>
<div class="MenuButton" style="margin-top: auto;" id="disconnectFromServer">
Disconnect</div>
</div>
</div>

<!-- Microbe stage GUI -->
<div id="topLevelMicrobeStage">

Expand Down
19 changes: 19 additions & 0 deletions scripts/microbe_stage/setup.as
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ void setupScriptsForWorld_Server(CellStageWorld@ world)
// setupSpawnSystem_Server(world);
}

//! Server variant of setupScriptsForWorld
void setupScriptsForWorld_Client(CellStageWorld@ world)
{
setupSystemsForWorld_Client(world);
}

// This function should be the entry point for all player initial-species generation
// For now, it can go through the XML and instantiate all the species, but later this
// would be all procedural.
Expand Down Expand Up @@ -100,6 +106,19 @@ void setupSystemsForWorld_Server(CellStageWorld@ world)
world.RegisterScriptSystem("MicrobeAISystem", MicrobeAISystem());
}

//! Client variant of setupSystemsForWorld
void setupSystemsForWorld_Client(CellStageWorld@ world)
{
// Fail if compound registry is empty //
assert(SimulationParameters::compoundRegistry().getSize() > 0,
"Compound registry is empty");

world.RegisterScriptComponentType("MicrobeComponent", @MicrobeComponentFactory);

world.RegisterScriptSystem("MicrobeSystem", MicrobeSystem());
world.RegisterScriptSystem("MicrobeStageHudSystem", MicrobeStageHudSystem());
}


//! This spawns the player
void setupPlayer(CellStageWorld@ world)
Expand Down
Loading

0 comments on commit 8b6bb4f

Please sign in to comment.