mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 22:38:38 +01:00
More stuff, started console
This commit is contained in:
parent
2eb09c1daa
commit
fc2f52099c
@ -137,3 +137,5 @@ src/interface/ControlFactory.cpp
|
||||
includes/interface/ControlFactory.h
|
||||
src/GameSession.cpp
|
||||
includes/GameSession.h
|
||||
src/Console.cpp
|
||||
includes/Console.h
|
||||
|
44
includes/Console.h
Normal file
44
includes/Console.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<ConsoleCommand> * 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<ConsoleCommand> * GetPreviousCommands();
|
||||
Console(ui::Sandbox * sandbox);
|
||||
virtual ~Console();
|
||||
};
|
||||
|
||||
#endif // CONSOLE_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);
|
||||
|
68
src/Console.cpp
Normal file
68
src/Console.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
|
||||
#include <string>
|
||||
#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 && i<PT_NUM && sim->ptypes[i].enabled)
|
||||
{
|
||||
(*lastError) = "";
|
||||
return i;
|
||||
}
|
||||
for (i=1; i<PT_NUM; i++) {
|
||||
if (strcasecmp(txt, sim->ptypes[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<ConsoleCommand> * Console::GetPreviousCommands()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Console::Console(ui::Sandbox * sandbox)
|
||||
{
|
||||
this->sandbox = sandbox;
|
||||
sim = sandbox->GetSimulation();
|
||||
}
|
||||
|
||||
Console::~Console()
|
||||
{
|
||||
|
||||
}
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -5,35 +5,54 @@
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user