Skip to content

Commit

Permalink
Remove Pi.cpp ship spawning behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sturnclaw committed Aug 2, 2020
1 parent 61f4981 commit 7738f7d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 84 deletions.
21 changes: 13 additions & 8 deletions data/modules/DebugShipSpawn/DebugShipSpawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ do_spawn_missile = function(type)
return true
end)
end
local ship_equip = {
Equipment.laser.pulsecannon_dual_1mw,
Equipment.misc.laser_cooling_booster,
Equipment.misc.atmospheric_shielding
}
local ship_spawn_debug_window
ship_spawn_debug_window = function()
ui.child('ship_list', Vector2(150, 0), draw_ship_types)
Expand All @@ -129,11 +134,6 @@ ship_spawn_debug_window = function()
if ship_name then
ship = ShipDef[ship_name]
end
local ship_equip = {
Equipment.laser.pulsecannon_dual_1mw,
Equipment.misc.laser_cooling_booster,
Equipment.misc.atmospheric_shielding
}
ui.sameLine()
if ship then
return ui.group(function()
Expand Down Expand Up @@ -170,18 +170,23 @@ ship_spawn_debug_window = function()
end)
end
end
return debug_ui.registerTab("Ship Spawner", function()
debug_ui.registerTab("Ship Spawner", function()
if not (Game.player and Game.CurrentView() == "world") then
return nil
end
if ui.beginTabItem("Ship Spawner") then
ship_spawn_debug_window()
ui.endTabItem()
if ui.isKeyReleased(string.byte('r')) and ui.ctrlHeld() then
package.reimport('.DebugShipSpawn')
return package.reimport('.DebugShipSpawn')
end
end
if ui.isKeyReleased(ui.keys.f12) and ui.ctrlHeld() then
end)
return ui.registerModule("game", function()
if not (Game.CurrentView() == "world") then
return nil
end
if ui.isKeyReleased(ui.keys.f12) and ui.ctrlHeld() then
return spawn_ship_free("kanara", "Kill", ship_equip)
end
end)
20 changes: 11 additions & 9 deletions data/modules/DebugShipSpawn/DebugShipSpawn.moon
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ do_spawn_missile = (type) ->

return true

ship_equip = {
Equipment.laser.pulsecannon_dual_1mw
Equipment.misc.laser_cooling_booster
Equipment.misc.atmospheric_shielding
}

ship_spawn_debug_window = ->
ui.child 'ship_list', Vector2(150, 0), draw_ship_types

ship_name = ship_defs[selected_ship_type]
ship = ShipDef[ship_name] if ship_name

ship_equip = {
Equipment.laser.pulsecannon_dual_1mw
Equipment.misc.laser_cooling_booster
Equipment.misc.atmospheric_shielding
}

ui.sameLine!
if ship then ui.group ->
spawner_group_height = ui.getFrameHeight! * 2 + ui.getFrameHeightWithSpacing!
Expand Down Expand Up @@ -160,7 +160,9 @@ debug_ui.registerTab "Ship Spawner", ->
if ui.isKeyReleased(string.byte 'r') and ui.ctrlHeld!
package.reimport '.DebugShipSpawn'

ui.registerModule "game", ->
unless Game.CurrentView() == "world"
return nil

if ui.isKeyReleased(ui.keys.f12) and ui.ctrlHeld!
-- TODO: port Pi.cpp ship spawning behavior here
-- do_spawn_ship()
nil
spawn_ship_free "kanara", "Kill", ship_equip
66 changes: 0 additions & 66 deletions src/Pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,6 @@ void Pi::StartGame(Game *game)
===============================================================================
*/

// FIXME: move out of Pi.cpp into a proper debug interface!
static void SpawnTestObjects();

void Pi::HandleKeyDown(SDL_Keysym *key)
{
if (key->sym == SDLK_ESCAPE) {
Expand Down Expand Up @@ -760,14 +757,6 @@ void Pi::HandleKeyDown(SDL_Keysym *key)
case SDLK_F11: // Reload shaders
renderer->ReloadShaders();
break;

case SDLK_F12: // Spawn
{
if (Pi::game)
SpawnTestObjects();

break;
}
#endif /* DEVKEYS */

#if WITH_OBJECTVIEWER
Expand Down Expand Up @@ -1334,61 +1323,6 @@ static void SetVideoRecording(bool enabled)
}
#endif

static void SpawnTestObjects()
{
vector3d dir = -Pi::player->GetOrient().VectorZ();
/* add test object */
if (Pi::input->KeyState(SDLK_RSHIFT)) {
Missile *missile =
new Missile(ShipType::MISSILE_GUIDED, Pi::player);
missile->SetOrient(Pi::player->GetOrient());
missile->SetFrame(Pi::player->GetFrame());
missile->SetPosition(Pi::player->GetPosition() + 50.0 * dir);
missile->SetVelocity(Pi::player->GetVelocity());
Pi::game->GetSpace()->AddBody(missile);
missile->AIKamikaze(Pi::player->GetCombatTarget());
} else if (Pi::input->KeyState(SDLK_LSHIFT)) {
SpaceStation *s = static_cast<SpaceStation *>(Pi::player->GetNavTarget());
if (s) {
Ship *ship = new Ship(ShipType::POLICE);
int port = s->GetFreeDockingPort(ship);
if (port != -1) {
Output("Putting ship into station\n");
// Make police ship intent on killing the player
ship->AIKill(Pi::player);
ship->SetFrame(Pi::player->GetFrame());
ship->SetDockedWith(s, port);
Pi::game->GetSpace()->AddBody(ship);
} else {
delete ship;
Output("No docking ports free dude\n");
}
} else {
Output("Select a space station...\n");
}
} else {
Ship *ship = new Ship(ShipType::POLICE);
if (!Pi::input->KeyState(SDLK_LALT)) { //Left ALT = no AI
if (!Pi::input->KeyState(SDLK_LCTRL))
ship->AIFlyTo(Pi::player); // a less lethal option
else
ship->AIKill(Pi::player); // a really lethal option!
}
lua_State *l = Lua::manager->GetLuaState();
pi_lua_import(l, "Equipment");
LuaTable equip(l, -1);
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("laser").Sub("pulsecannon_dual_1mw"));
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("laser_cooling_booster"));
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("atmospheric_shielding"));
lua_pop(l, 5);
ship->SetFrame(Pi::player->GetFrame());
ship->SetPosition(Pi::player->GetPosition() + 100.0 * dir);
ship->SetVelocity(Pi::player->GetVelocity());
ship->UpdateEquipStats();
Pi::game->GetSpace()->AddBody(ship);
}
}

void printShipStats()
{
// test code to produce list of ship stats
Expand Down
6 changes: 5 additions & 1 deletion src/pigui/PerfInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "graphics/Texture.h"
#include "lua/Lua.h"
#include "lua/LuaManager.h"
#include "scenegraph/Model.h"
#include "lua/LuaPiGui.h"
#include "scenegraph/Model.h"
#include "text/TextureFont.h"

#include <imgui/imgui.h>
Expand Down Expand Up @@ -283,6 +283,10 @@ void PerfInfo::DrawRendererStats()

if (ImGui::Button("Open Texture Cache Visualizer"))
m_state->textureCacheViewerOpen = true;

if (ImGui::Button("Reload Shaders"))
Pi::renderer->ReloadShaders();

ImGui::Text("%u Texture2D in cache (%.3f MB)", numTex2ds, double(tex2dMemUsage) / scale_MB);
ImGui::Text("%u Cubemaps in cache (%.3f MB)", numTexCubemaps, double(texCubeMemUsage) / scale_MB);
ImGui::Text("%u TextureArray2D in cache (%.3f MB)", numTexArray2ds, double(texArray2dMemUsage) / scale_MB);
Expand Down

0 comments on commit 7738f7d

Please sign in to comment.