From fc2f52099c0bbb2412046252bf7b5e4113bbe8e4 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 11 Jan 2012 22:59:45 +0000 Subject: More stuff, started console diff --git a/PowderToy++.files b/PowderToy++.files index a6f35ab..62d6e2a 100644 --- a/PowderToy++.files +++ b/PowderToy++.files @@ -137,3 +137,5 @@ src/interface/ControlFactory.cpp includes/interface/ControlFactory.h src/GameSession.cpp includes/GameSession.h +src/Console.cpp +includes/Console.h diff --git a/includes/Console.h b/includes/Console.h new file mode 100644 index 0000000..806c4db --- /dev/null +++ b/includes/Console.h @@ -0,0 +1,44 @@ +#ifndef CONSOLE_H +#define CONSOLE_H + +#include +#include + +#include "interface/Sandbox.h" +#include "Simulation.h" + +class ConsoleCommand +{ +private: + std::string * command; + int returnStatus; + std::string * error; +public: + void SetCommand(std::string * command); + void SetError(std::string * error); + std::string * GetCommand(); + std::string * GetError(); + ConsoleCommand(); + ConsoleCommand(std::string * command, int returnStatus, std::string * error = new std::string("")); +}; + +class Console +{ +private: + std::vector * previousCommands; + std::string * lastError; + ui::Sandbox * sandbox; + Simulation * sim; +public: + virtual void Tick(float * dt); + int ParseType(std::string * type); + virtual void ConsoleShown(); + virtual void ConsoleHidden(); + virtual int ProcessCommand(std::string * command); + virtual std::string * GetLastError(); + virtual std::vector * GetPreviousCommands(); + Console(ui::Sandbox * sandbox); + virtual ~Console(); +}; + +#endif // CONSOLE_H diff --git a/includes/interface/Sandbox.h b/includes/interface/Sandbox.h index 10d588f..32a0471 100644 --- a/includes/interface/Sandbox.h +++ b/includes/interface/Sandbox.h @@ -16,11 +16,14 @@ namespace ui { class Sandbox: public ui::Component { private: + int lastCoordX, lastCoordY; + int activeElement; bool isMouseDown; Renderer * ren; Simulation * sim; public: Sandbox(); + virtual Simulation * GetSimulation(); virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy); virtual void OnMouseDown(int localx, int localy, unsigned int button); virtual void OnMouseUp(int localx, int localy, unsigned int button); diff --git a/src/Console.cpp b/src/Console.cpp new file mode 100644 index 0000000..6bf8ce6 --- /dev/null +++ b/src/Console.cpp @@ -0,0 +1,68 @@ + +#include +#include "Console.h" + +int Console::ParseType(std::string * type) +{ + char * txt = (char *)type->c_str(); + int i = -1; + // alternative names for some elements + if (*type == "C4") i = PT_PLEX; + else if (*type == "C5") i = PT_C5; + else if (*type == "NONE") i = PT_NONE; + if (i>=0 && iptypes[i].enabled) + { + (*lastError) = ""; + return i; + } + for (i=1; iptypes[i].name)==0 && sim->ptypes[i].enabled) + { + (*lastError) = ""; + return i; + } + } + (*lastError) = "Particle type not recognised"; + return -1; +} + +void Console::Tick(float * dt) +{ + +} + +void Console::ConsoleShown() +{ + +} + +void Console::ConsoleHidden() +{ + +} + +int Console::ProcessCommand(std::string * command) +{ + +} + +std::string * Console::GetLastError() +{ + return lastError; +} + +std::vector * Console::GetPreviousCommands() +{ + +} + +Console::Console(ui::Sandbox * sandbox) +{ + this->sandbox = sandbox; + sim = sandbox->GetSimulation(); +} + +Console::~Console() +{ + +} diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp index 973aaa3..49dac73 100644 --- a/src/PowderToy.cpp +++ b/src/PowderToy.cpp @@ -54,12 +54,12 @@ int main(int argc, char * argv[]) ui::Button * button = new ui::Button(100, 100, 100, 100, "poP"); window->Add(sandbox); window->Add(button); - window->Add(ControlFactory::MainMenu(gameSession, 0, 0, 200, 200)); + //window->Add(ControlFactory::MainMenu(gameSession, 0, 0, 200, 200)); SDL_Event event; while(!SDLPoll(&event)) { - mouseButton = SDL_GetMouseState(&mouseX, &mouseY); + //mouseButton = SDL_GetMouseState(&mouseX, &mouseY); switch(event.type) { case SDL_KEYDOWN: diff --git a/src/Renderer.cpp b/src/Renderer.cpp index c1bbf3c..67f9348 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -489,9 +489,14 @@ void Renderer::render_parts() int deca, decr, decg, decb, cola, colr, colg, colb, firea, firer, fireg, fireb, pixel_mode, q, i, t, nx, ny, x, y, caddress; int orbd[4] = {0, 0, 0, 0}, orbl[4] = {0, 0, 0, 0}; float gradv, flicker, fnx, fny; - Particle * parts = sim->parts; - part_transition *ptransitions = sim->ptransitions; - part_type *ptypes = sim->ptypes; + Particle * parts; + part_transition *ptransitions; + part_type *ptypes; + if(!sim) + return; + parts = sim->parts; + ptransitions = sim->ptransitions; + ptypes = sim->ptypes; #ifdef OGLR int cfireV = 0, cfireC = 0, cfire = 0; int csmokeV = 0, csmokeC = 0, csmoke = 0; @@ -1670,7 +1675,9 @@ void Renderer::init_display_modes() } } -Renderer::Renderer(Graphics * g, Simulation * sim) +Renderer::Renderer(Graphics * g, Simulation * sim): + sim(NULL), + g(NULL) { this->g = g; this->sim = sim; diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 7ec5c4e..a1a785a 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -3119,6 +3119,8 @@ void Simulation::update_particles()//doesn't update the particles themselves, bu pthread_t *InterThreads; #endif + air->update_air(); + memset(pmap, 0, sizeof(pmap)); memset(photons, 0, sizeof(photons)); NUM_PARTS = 0; diff --git a/src/interface/Sandbox.cpp b/src/interface/Sandbox.cpp index c33571a..5e29bae 100644 --- a/src/interface/Sandbox.cpp +++ b/src/interface/Sandbox.cpp @@ -5,35 +5,54 @@ * Author: Simon */ +#include + #include "Config.h" #include "interface/Sandbox.h" #include "interface/Component.h" #include "Renderer.h" +#include "Simulation.h" namespace ui { Sandbox::Sandbox(): - Component(0, 0, XRES, YRES) + Component(0, 0, XRES, YRES), + ren(NULL), + isMouseDown(false), + activeElement(1) { sim = new Simulation(); } +Simulation * Sandbox::GetSimulation() +{ + return sim; +} + void Sandbox::OnMouseMovedInside(int localx, int localy, int dx, int dy) { if(isMouseDown) { - sim->create_parts(localx, localy, 20, 20, 1, 0); + sim->create_line(lastCoordX, lastCoordY, localx, localy, 2, 2, activeElement, 0); + lastCoordX = localx; + lastCoordY = localy; } } void Sandbox::OnMouseDown(int localx, int localy, unsigned int button) { + sim->create_line(localx, localy, localx, localy, 2, 2, activeElement, 0); + lastCoordX = localx; + lastCoordY = localy; isMouseDown = true; } void Sandbox::OnMouseUp(int localx, int localy, unsigned int button) { + sim->create_line(lastCoordX, lastCoordY, localx, localy, 2, 2, activeElement, 0); + lastCoordX = localx; + lastCoordY = localy; isMouseDown = false; } diff --git a/src/interface/State.cpp b/src/interface/State.cpp index e069e8f..2828751 100644 --- a/src/interface/State.cpp +++ b/src/interface/State.cpp @@ -13,13 +13,14 @@ namespace ui { -State::State(int w, int h) : - mouseX(0), - mouseY(0), - mouseXP(0), - mouseYP(0), - width(w), - height(h) +State::State(int w, int h): + mouseX(0), + mouseY(0), + mouseXP(0), + mouseYP(0), + width(w), + height(h), + Components() { } -- cgit v0.9.2-21-gd62e