summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--PowderToy++.files22
-rw-r--r--src/Console.h2
-rw-r--r--src/Graphics.cpp39
-rw-r--r--src/Misc.h10
-rw-r--r--src/PowderToy.cpp5
-rw-r--r--src/Renderer.cpp8
-rw-r--r--src/Renderer.h2
-rw-r--r--src/client/Client.cpp133
-rw-r--r--src/client/Client.h24
-rw-r--r--src/client/HTTP.cpp1076
-rw-r--r--src/client/HTTP.h43
-rw-r--r--src/client/MD5.cpp231
-rw-r--r--src/client/MD5.h18
-rw-r--r--src/elements/O2.cpp2
-rw-r--r--src/elements/acel.cpp2
-rw-r--r--src/elements/acid.cpp2
-rw-r--r--src/elements/amtr.cpp2
-rw-r--r--src/elements/anar.cpp2
-rw-r--r--src/elements/aray.cpp2
-rw-r--r--src/elements/bang.cpp2
-rw-r--r--src/elements/bcln.cpp2
-rw-r--r--src/elements/bcol.cpp2
-rw-r--r--src/elements/bizr.cpp2
-rw-r--r--src/elements/bmtl.cpp2
-rw-r--r--src/elements/bomb.cpp2
-rw-r--r--src/elements/boyl.cpp2
-rw-r--r--src/elements/brmt.cpp2
-rw-r--r--src/elements/btry.cpp2
-rw-r--r--src/elements/c5.cpp2
-rw-r--r--src/elements/caus.cpp2
-rw-r--r--src/elements/cbnw.cpp2
-rw-r--r--src/elements/clne.cpp2
-rw-r--r--src/elements/clst.cpp2
-rw-r--r--src/elements/co2.cpp2
-rw-r--r--src/elements/coal.cpp2
-rw-r--r--src/elements/conv.cpp2
-rw-r--r--src/elements/dest.cpp2
-rw-r--r--src/elements/deut.cpp2
-rw-r--r--src/elements/dlay.cpp2
-rw-r--r--src/elements/dstw.cpp2
-rw-r--r--src/elements/elec.cpp2
-rw-r--r--src/elements/elementmisc.cpp2
-rw-r--r--src/elements/emp.cpp2
-rw-r--r--src/elements/figh.cpp2
-rw-r--r--src/elements/fire.cpp2
-rw-r--r--src/elements/firw.cpp2
-rw-r--r--src/elements/fog.cpp2
-rw-r--r--src/elements/frzw.cpp2
-rw-r--r--src/elements/frzz.cpp2
-rw-r--r--src/elements/fsep.cpp2
-rw-r--r--src/elements/fuse.cpp2
-rw-r--r--src/elements/fwrk.cpp2
-rw-r--r--src/elements/gbmb.cpp2
-rw-r--r--src/elements/glas.cpp2
-rw-r--r--src/elements/glow.cpp2
-rw-r--r--src/elements/goo.cpp2
-rw-r--r--src/elements/gpmp.cpp2
-rw-r--r--src/elements/graphics_default.cpp2
-rw-r--r--src/elements/h2.cpp2
-rw-r--r--src/elements/hswc.cpp2
-rw-r--r--src/elements/ice.cpp2
-rw-r--r--src/elements/ignt.cpp2
-rw-r--r--src/elements/iron.cpp2
-rw-r--r--src/elements/isz.cpp2
-rw-r--r--src/elements/lava.cpp2
-rw-r--r--src/elements/lcry.cpp2
-rw-r--r--src/elements/legacy.cpp2
-rw-r--r--src/elements/ligh.cpp2
-rw-r--r--src/elements/merc.cpp2
-rw-r--r--src/elements/mort.cpp2
-rw-r--r--src/elements/nbhl.cpp2
-rw-r--r--src/elements/neut.cpp2
-rw-r--r--src/elements/newgraphics.cpp2
-rw-r--r--src/elements/none.cpp2
-rw-r--r--src/elements/nptct.cpp2
-rw-r--r--src/elements/nwhl.cpp2
-rw-r--r--src/elements/pbcn.cpp2
-rw-r--r--src/elements/pcln.cpp2
-rw-r--r--src/elements/phot.cpp2
-rw-r--r--src/elements/pipe.cpp2
-rw-r--r--src/elements/plnt.cpp2
-rw-r--r--src/elements/plsm.cpp2
-rw-r--r--src/elements/plut.cpp2
-rw-r--r--src/elements/prti.cpp2
-rw-r--r--src/elements/prto.cpp2
-rw-r--r--src/elements/pump.cpp2
-rw-r--r--src/elements/pvod.cpp2
-rw-r--r--src/elements/pyro.cpp2
-rw-r--r--src/elements/qrtz.cpp2
-rw-r--r--src/elements/rime.cpp2
-rw-r--r--src/elements/shld.cpp2
-rw-r--r--src/elements/sing.cpp2
-rw-r--r--src/elements/sltw.cpp2
-rw-r--r--src/elements/smke.cpp2
-rw-r--r--src/elements/soap.cpp2
-rw-r--r--src/elements/spng.cpp2
-rw-r--r--src/elements/sprk.cpp2
-rw-r--r--src/elements/stkm.cpp2
-rw-r--r--src/elements/stkm2.cpp2
-rw-r--r--src/elements/stor.cpp2
-rw-r--r--src/elements/swch.cpp2
-rw-r--r--src/elements/thdr.cpp2
-rw-r--r--src/elements/thrm.cpp2
-rw-r--r--src/elements/uran.cpp2
-rw-r--r--src/elements/vine.cpp2
-rw-r--r--src/elements/warp.cpp2
-rw-r--r--src/elements/watr.cpp2
-rw-r--r--src/elements/wifi.cpp2
-rw-r--r--src/elements/wire.cpp2
-rw-r--r--src/elements/wtrv.cpp2
-rw-r--r--src/elements/yest.cpp2
-rw-r--r--src/game/GameController.cpp7
-rw-r--r--src/game/GameController.h3
-rw-r--r--src/game/GameModel.cpp2
-rw-r--r--src/game/GameModel.h2
-rw-r--r--src/game/GameView.cpp15
-rw-r--r--src/game/GameView.h9
-rw-r--r--src/interface/Button.cpp64
-rw-r--r--src/interface/Button.h12
-rw-r--r--src/interface/Engine.cpp3
-rw-r--r--src/interface/Sandbox.cpp101
-rw-r--r--src/interface/Sandbox.h39
-rw-r--r--src/interface/SaveButton.cpp157
-rw-r--r--src/interface/SaveButton.h50
-rw-r--r--src/search/Save.h5
-rw-r--r--src/search/SearchController.cpp3
-rw-r--r--src/search/SearchController.h5
-rw-r--r--src/search/SearchModel.cpp16
-rw-r--r--src/search/SearchModel.h3
-rw-r--r--src/search/SearchView.cpp54
-rw-r--r--src/search/SearchView.h17
-rw-r--r--src/search/Thumbnail.h49
-rw-r--r--src/simulation/Air.cpp (renamed from src/Air.cpp)0
-rw-r--r--src/simulation/Air.h (renamed from src/Air.h)0
-rw-r--r--src/simulation/Element.h (renamed from src/Element.h)0
-rw-r--r--src/simulation/ElementFunctions.h (renamed from src/ElementFunctions.h)0
-rw-r--r--src/simulation/ElementGraphics.h (renamed from src/ElementGraphics.h)0
-rw-r--r--src/simulation/Elements.h (renamed from src/Elements.h)0
-rw-r--r--src/simulation/Gravity.cpp (renamed from src/Gravity.cpp)0
-rw-r--r--src/simulation/Gravity.h (renamed from src/Gravity.h)0
-rw-r--r--src/simulation/Simulation.cpp (renamed from src/Simulation.cpp)0
-rw-r--r--src/simulation/Simulation.h (renamed from src/Simulation.h)0
143 files changed, 2128 insertions, 301 deletions
diff --git a/Makefile b/Makefile
index 4d20bfc..43fa157 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@ OBJS += $(patsubst src/%.cpp,build/obj/powder.exe/%.o,$(SOURCES))
FOLDERS := $(sort $(dir $(OBJS)))
-CFLAGS := -Wno-deprecated -Wno-deprecated-declarations -Isrc/ -Idata/ -DWIN32 -DWINCONSOLE
-OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -msse2 -fkeep-inline-functions
+CFLAGS := -w -Isrc/ -Idata/ -DWIN32 -DWINCONSOLE
+OFLAGS := -fkeep-inline-functions #-O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -msse2
LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 # -mwindows
CFLAGS += $(OFLAGS)
diff --git a/PowderToy++.files b/PowderToy++.files
index 5a30285..af47ebb 100644
--- a/PowderToy++.files
+++ b/PowderToy++.files
@@ -140,7 +140,6 @@ includes/Console.h
includes/interface/Engine.h
includes/interface/Platform.h
src/interface/State.cpp
-src/interface/Sandbox.cpp
src/interface/Panel.cpp
src/interface/Engine.cpp
src/interface/ControlFactory.cpp
@@ -290,7 +289,6 @@ src/elements/acid.cpp
src/elements/acel.cpp
src/interface/Window.h
src/interface/State.h
-src/interface/Sandbox.h
src/interface/Point.h
src/interface/Platform.h
src/interface/Panel.h
@@ -308,3 +306,23 @@ src/interface/Engine.cpp
src/interface/ControlFactory.cpp
src/interface/Component.cpp
src/interface/Button.cpp
+src/interface/SaveButton.h
+src/interface/SaveButton.cpp
+src/client/Client.h
+src/client/Client.cpp
+src/client/HTTP.h
+src/client/HTTP.c
+src/client/HTTP.cpp
+src/client/MD5.cpp
+src/client/MD5.h
+src/search/Thumbnail.h
+src/simulation/Simulation.h
+src/simulation/Gravity.h
+src/simulation/Elements.h
+src/simulation/ElementGraphics.h
+src/simulation/ElementFunctions.h
+src/simulation/Element.h
+src/simulation/Air.h
+src/simulation/Simulation.cpp
+src/simulation/Gravity.cpp
+src/simulation/Air.cpp
diff --git a/src/Console.h b/src/Console.h
index 657f935..8f7a072 100644
--- a/src/Console.h
+++ b/src/Console.h
@@ -5,7 +5,7 @@
#include <vector>
#include "interface/Sandbox.h"
-#include "Simulation.h"
+#include "simulation/Simulation.h"
class ConsoleCommand
{
diff --git a/src/Graphics.cpp b/src/Graphics.cpp
index 52fa4c9..65d198f 100644
--- a/src/Graphics.cpp
+++ b/src/Graphics.cpp
@@ -19,13 +19,13 @@
#endif
#include "Config.h"
-#include "air.h"
-#include "gravity.h"
+//#include "simulation/Air.h"
+//#include "simulation/Gravity.h"
//#include "powder.h"
-#define INCLUDE_PSTRUCT
-#include "Simulation.h"
-#include "Graphics.h"
-#include "ElementGraphics.h"
+//#define INCLUDE_PSTRUCT
+//#include "Simulation.h"
+//#include "Graphics.h"
+//#include "ElementGraphics.h"
#define INCLUDE_FONTDATA
#include "font.h"
#include "misc.h"
@@ -1501,15 +1501,24 @@ void Graphics::draw_image(pixel *img, int x, int y, int w, int h, int a)
{
int i, j, r, g, b;
if (!img) return;
- for (j=0; j<h; j++)
- for (i=0; i<w; i++)
- {
- r = PIXR(*img);
- g = PIXG(*img);
- b = PIXB(*img);
- drawpixel(x+i, y+j, r, g, b, a);
- img++;
- }
+ if(y + h > YRES+MENUSIZE) h = (YRES+MENUSIZE)-y; //Adjust height to prevent drawing off the bottom
+ if(a >= 255)
+ for (j=0; j<h; j++)
+ for (i=0; i<w; i++)
+ {
+ vid[(y+j)*(XRES+BARSIZE)+(x+i)] = *img;
+ img++;
+ }
+ else
+ for (j=0; j<h; j++)
+ for (i=0; i<w; i++)
+ {
+ r = PIXR(*img);
+ g = PIXG(*img);
+ b = PIXB(*img);
+ drawpixel(x+i, y+j, r, g, b, a);
+ img++;
+ }
}
void Graphics::dim_copy(pixel *dst, pixel *src) //old persistent, unused
diff --git a/src/Misc.h b/src/Misc.h
index c5a61ef..65ae5b3 100644
--- a/src/Misc.h
+++ b/src/Misc.h
@@ -3,6 +3,16 @@
#include <stdio.h>
#include <stdlib.h>
+enum HorizontalAlignment
+{
+ AlignLeft, AlignCentre, AlignRight
+};
+
+enum VerticalAlignment
+{
+ AlignTop, AlignMiddle, AlignBottom
+};
+
#if defined(WIN32) && !defined(__GNUC__)
#define x86_cpuid(func,af,bf,cf,df) \
do {\
diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp
index cf7d804..0ee1648 100644
--- a/src/PowderToy.cpp
+++ b/src/PowderToy.cpp
@@ -6,10 +6,7 @@
#include <string>
#include "Config.h"
#include "Global.h"
-#include "Simulation.h"
-#include "Renderer.h"
#include "Graphics.h"
-#include "Air.h"
#include "interface/Engine.h"
#include "interface/Button.h"
@@ -22,6 +19,8 @@
#include "game/GameController.h"
#include "game/GameView.h"
+#include "client/HTTP.h"
+
using namespace std;
SDL_Surface * SDLOpen()
diff --git a/src/Renderer.cpp b/src/Renderer.cpp
index 67f9348..2644924 100644
--- a/src/Renderer.cpp
+++ b/src/Renderer.cpp
@@ -9,10 +9,10 @@
#include "Config.h"
#include "Renderer.h"
#include "Graphics.h"
-#include "Elements.h"
-#include "ElementFunctions.h"
-#include "ElementGraphics.h"
-#include "Air.h"
+#include "simulation/Elements.h"
+#include "simulation/ElementFunctions.h"
+#include "simulation/ElementGraphics.h"
+#include "simulation/Air.h"
extern "C"
{
#include "hmap.h"
diff --git a/src/Renderer.h b/src/Renderer.h
index 39c8c1a..a756f13 100644
--- a/src/Renderer.h
+++ b/src/Renderer.h
@@ -2,7 +2,7 @@
#define RENDERER_H
#include "Config.h"
-#include "Simulation.h"
+#include "simulation/Simulation.h"
#include "Graphics.h"
class Simulation;
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
new file mode 100644
index 0000000..3545414
--- /dev/null
+++ b/src/client/Client.cpp
@@ -0,0 +1,133 @@
+#include <stdlib.h>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include "Config.h"
+#include "Client.h"
+#include "interface/Point.h"
+#include "Graphics.h"
+
+/*
+ static Thumbnail* thumbnailCache[120];
+ static void * activeThumbRequests[5];
+ static int activeThumbRequestTimes[5];
+ static std::string activeThumbRequestIDs[5];
+*/
+
+Client::Client()
+{
+ int i = 0;
+ http_init(NULL);
+ for(i = 0; i < 120; i++)
+ {
+ thumbnailCache[i] = NULL;
+ }
+ for(i = 0; i < 5; i++)
+ {
+ activeThumbRequests[i] = NULL;
+ activeThumbRequestTimes[i] = 0;
+ }
+}
+
+Client::~Client()
+{
+ http_done();
+}
+
+void Client::ClearThumbnailRequests()
+{
+ for(int i = 0; i < 5; i++)
+ {
+ if(activeThumbRequests[i])
+ {
+ http_async_req_close(activeThumbRequests[i]);
+ activeThumbRequests[i] = NULL;
+ }
+ }
+}
+
+Thumbnail * Client::GetThumbnail(int saveID, int saveDate)
+{
+ std::stringstream urlStream;
+ std::stringstream idStream;
+ int i = 0;
+ for(i = 0; i < 120; i++)
+ {
+ if(thumbnailCache[i] && thumbnailCache[i]->ID == saveID && thumbnailCache[i]->Datestamp == saveDate)
+ return thumbnailCache[i];
+ }
+ urlStream << "http://" << SERVER << "/Get.api?Op=thumbsmall&ID=" << saveID;
+ if(saveDate)
+ {
+ urlStream << "&Date=" << saveDate;
+ }
+ idStream << saveID << ":" << saveDate;
+ std::string idString = idStream.str();
+ bool found = false;
+ for(i = 0; i < 5; i++)
+ {
+ if(activeThumbRequests[i] && activeThumbRequestIDs[i] == idString)
+ {
+ found = true;
+ if(http_async_req_status(activeThumbRequests[i]))
+ {
+ pixel * thumbData;
+ char * data;
+ int status, data_size, imgw, imgh;
+ data = http_async_req_stop(activeThumbRequests[i], &status, &data_size);
+ activeThumbRequests[i] = NULL;
+ if (status == 200 && data)
+ {
+ thumbData = Graphics::ptif_unpack(data, data_size, &imgw, &imgh);
+ if(data)
+ {
+ free(data);
+ }
+ thumbnailCacheNextID %= 120;
+ if(thumbnailCache[thumbnailCacheNextID])
+ {
+ delete thumbnailCache[thumbnailCacheNextID];
+ }
+ if(thumbData)
+ {
+ thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, thumbData, ui::Point(imgw, imgh));
+ }
+ else
+ {
+ thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
+ }
+ return thumbnailCache[thumbnailCacheNextID++];
+ }
+ else
+ {
+ if(data)
+ {
+ free(data);
+ }
+ thumbnailCacheNextID %= 120;
+ if(thumbnailCache[thumbnailCacheNextID])
+ {
+ delete thumbnailCache[thumbnailCacheNextID];
+ }
+ thumbnailCache[thumbnailCacheNextID] = new Thumbnail(saveID, saveDate, (pixel *)malloc((128*128) * PIXELSIZE), ui::Point(128, 128));
+ return thumbnailCache[thumbnailCacheNextID++];
+ }
+ }
+ }
+ }
+ if(!found)
+ {
+ for(i = 0; i < 5; i++)
+ {
+ if(!activeThumbRequests[i])
+ {
+ activeThumbRequests[i] = http_async_req_start(NULL, (char *)urlStream.str().c_str(), NULL, 0, 1);
+ std::cout << "ThumbCache: Requesting " << urlStream.str() << " : " << idString << std::endl;
+ activeThumbRequestIDs[i] = idString;
+ return NULL;
+ }
+ }
+ }
+ //http_async_req_start(http, urlStream.str().c_str(), NULL, 0, 1);
+ return NULL;
+}
diff --git a/src/client/Client.h b/src/client/Client.h
new file mode 100644
index 0000000..37d0ad6
--- /dev/null
+++ b/src/client/Client.h
@@ -0,0 +1,24 @@
+#ifndef CLIENT_H
+#define CLIENT_H
+
+#include <queue>
+#include "HTTP.h"
+#include "search/Thumbnail.h"
+#include "Singleton.h"
+
+class Client: public Singleton<Client>
+{
+private:
+ int thumbnailCacheNextID;
+ Thumbnail * thumbnailCache[120];
+ void * activeThumbRequests[5];
+ int activeThumbRequestTimes[5];
+ std::string activeThumbRequestIDs[5];
+public:
+ Client();
+ ~Client();
+ void ClearThumbnailRequests();
+ Thumbnail * GetThumbnail(int saveID, int saveDate);
+};
+
+#endif // CLIENT_H
diff --git a/src/client/HTTP.cpp b/src/client/HTTP.cpp
new file mode 100644
index 0000000..7514515
--- /dev/null
+++ b/src/client/HTTP.cpp
@@ -0,0 +1,1076 @@
+/**
+ * Powder Toy - HTTP Library
+ *
+ * Copyright (c) 2008 - 2010 Stanislaw Skowronek.
+ * Copyright (c) 2010 Simon Robertshaw
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifndef MACOSX
+#include <malloc.h>
+#endif
+#include <time.h>
+#ifdef WIN32
+#define _WIN32_WINNT 0x0501
+//#include <iphlpapi.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#else
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#endif
+
+#include "Config.h"
+#include "HTTP.h"
+#include "MD5.h"
+
+#ifdef WIN32
+#define PERROR SOCKET_ERROR
+#define PERRNO WSAGetLastError()
+#define PEAGAIN WSAEWOULDBLOCK
+#define PEINTR WSAEINTR
+#define PEINPROGRESS WSAEINPROGRESS
+#define PEALREADY WSAEALREADY
+#define PCLOSE closesocket
+#else
+#define PERROR -1
+#define PERRNO errno
+#define PEAGAIN EAGAIN
+#define PEINTR EINTR
+#define PEINPROGRESS EINPROGRESS
+#define PEALREADY EALREADY
+#define PCLOSE close
+#endif
+
+static int http_up = 0;
+static long http_timeout = 15;
+static int http_use_proxy = 0;
+static struct sockaddr_in http_proxy;
+
+static char *mystrdup(char *s)
+{
+ char *x;
+ if (s)
+ {
+ x = (char *)malloc(strlen(s)+1);
+ strcpy(x, s);
+ return x;
+ }
+ return s;
+}
+
+static int splituri(char *uri, char **host, char **path)
+{
+ char *p=uri,*q,*x,*y;
+ if (!strncmp(p, "http://", 7))
+ p += 7;
+ q = strchr(p, '/');
+ if (!q)
+ q = p + strlen(p);
+ x = (char *)malloc(q-p+1);
+ if (*q)
+ y = mystrdup(q);
+ else
+ y = mystrdup("/");
+ strncpy(x, p, q-p);
+ x[q-p] = 0;
+ if (q==p || x[q-p-1]==':')
+ {
+ free(x);
+ free(y);
+ return 1;
+ }
+ *host = x;
+ *path = y;
+ return 0;
+}
+
+static char *getserv(char *host)
+{
+ char *q, *x = mystrdup(host);
+ q = strchr(x, ':');
+ if (q)
+ *q = 0;
+ return x;
+}
+
+static char *getport(char *host)
+{
+ char *p, *q;
+ q = strchr(host, ':');
+ if (q)
+ p = mystrdup(q+1);
+ else
+ p = mystrdup("80");
+ return p;
+}
+
+static int resolve(char *dns, char *srv, struct sockaddr_in *addr)
+{
+ struct addrinfo hnt, *res = 0;
+ if (http_use_proxy)
+ {
+ memcpy(addr, &http_proxy, sizeof(struct sockaddr_in));
+ return 0;
+ }
+ memset(&hnt, 0, sizeof(hnt));
+ hnt.ai_family = AF_INET;
+ hnt.ai_socktype = SOCK_STREAM;
+ if (getaddrinfo(dns, srv, &hnt, &res))
+ return 1;
+ if (res)
+ {
+ if (res->ai_family != AF_INET)
+ {
+ freeaddrinfo(res);
+ return 1;
+ }
+ memcpy(addr, res->ai_addr, res->ai_addrlen);
+ freeaddrinfo(res);
+ return 0;
+ }
+ return 1;
+}
+
+void http_init(char *proxy)
+{
+ char *host, *port;
+#ifdef WIN32
+ WSADATA wsadata;
+ if (!WSAStartup(MAKEWORD(2,2), &wsadata))
+ http_up = 1;
+#else
+ signal(SIGPIPE, SIG_IGN);
+ http_up = 1;
+#endif
+ if (proxy)
+ {
+ host = getserv(proxy);
+ port = getport(proxy);
+ if (resolve(host, port, &http_proxy))
+ http_up = 0;
+ else
+ http_use_proxy = 1;
+ free(host);
+ free(port);
+ }
+}
+
+void http_done(void)
+{
+#ifdef WIN32
+ WSACleanup();
+#endif
+ http_up = 0;
+}
+
+#define CHUNK 4096
+
+#define HTS_STRT 0
+#define HTS_RSLV 1
+#define HTS_CONN 2
+#define HTS_IDLE 3
+#define HTS_XMIT 4
+#define HTS_RECV 5
+#define HTS_DONE 6
+struct http_ctx
+{
+ int state;
+ time_t last;
+ int keep;
+ int ret;
+ char *host, *path;
+ char *thdr;
+ int thlen;
+ char *txd;
+ int txdl;
+ struct sockaddr_in addr;
+ char *tbuf;
+ int tlen, tptr;
+ char *hbuf;
+ int hlen, hptr;
+ char *rbuf;
+ int rlen, rptr;
+ int chunked, chunkhdr, rxtogo, contlen, cclose;
+ int fd;
+ char *fdhost;
+};
+void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
+{
+ struct http_ctx *cx = (http_ctx *)ctx;
+ if (!ctx)
+ {
+ ctx = calloc(1, sizeof(struct http_ctx));
+ cx = (http_ctx *)ctx;
+ cx->fd = PERROR;
+ }
+
+ if (!cx->hbuf)
+ {
+ cx->hbuf = (char *)malloc(256);
+ cx->hlen = 256;
+ }
+
+ if (!http_up)
+ {
+ cx->ret = 604;
+ cx->state = HTS_DONE;
+ return ctx;
+ }
+
+ if (cx->state!=HTS_STRT && cx->state!=HTS_IDLE)
+ {
+ fprintf(stderr, "HTTP: unclean request restart state.\n");
+ exit(1);
+ }
+
+ cx->keep = keep;
+ cx->ret = 600;
+ if (splituri(uri, &cx->host, &cx->path))
+ {
+ cx->ret = 601;
+ cx->state = HTS_DONE;
+ return ctx;
+ }
+ if (http_use_proxy)
+ {
+ free(cx->path);
+ cx->path = mystrdup(uri);
+ }
+ if (cx->fdhost && strcmp(cx->host, cx->fdhost))
+ {
+ free(cx->fdhost);
+ cx->fdhost = NULL;
+ PCLOSE(cx->fd);
+ cx->fd = PERROR;
+ cx->state = HTS_STRT;
+ }
+ if (data)
+ {
+ if (!dlen)
+ dlen = strlen(data);
+ cx->txd = (char*)malloc(dlen);
+ memcpy(cx->txd, data, dlen);
+ cx->txdl = dlen;
+ }
+ else
+ cx->txdl = 0;
+
+ cx->contlen = 0;
+ cx->chunked = 0;
+ cx->chunkhdr = 0;
+ cx->rxtogo = 0;
+ cx->cclose = 0;
+
+ cx->tptr = 0;
+ cx->tlen = 0;
+
+ cx->last = time(NULL);
+
+ return ctx;
+}
+
+void http_async_add_header(void *ctx, char *name, char *data)
+{
+ struct http_ctx *cx = (http_ctx *)ctx;
+ cx->thdr = (char *)realloc(cx->thdr, cx->thlen + strlen(name) + strlen(data) + 4);
+ cx->thlen += sprintf(cx->thdr+cx->thlen, "%s: %s\n", name, data);
+}
+
+static void process_header(struct http_ctx *cx, char *str)
+{
+ char *p;
+ if (cx->chunkhdr)
+ {
+ p = strchr(str, ';');
+ if (p)
+ *p = 0;
+ cx->rxtogo = strtoul(str, NULL, 16);
+ cx->chunkhdr = 0;
+ if (!cx->rxtogo)
+ cx->chunked = 0;
+ }
+ if (!str[0])
+ {
+ cx->rxtogo = cx->contlen;
+ cx->chunkhdr = cx->chunked;
+ if (!cx->contlen && !cx->chunked && cx->ret!=100)
+ cx->state = HTS_DONE;
+ return;
+ }
+ if (!strncmp(str, "HTTP/", 5))
+ {
+ p = strchr(str, ' ');
+ if (!p)
+ {
+ cx->ret = 603;
+ cx->state = HTS_DONE;
+ return;
+ }
+ p++;
+ cx->ret = atoi(p);
+ return;
+ }
+ if (!strncmp(str, "Content-Length: ", 16))
+ {
+ cx->contlen = atoi(str+16);
+ return;
+ }
+ if (!strcmp(str, "Transfer-Encoding: chunked"))
+ {
+ cx->chunked = 1;
+ return;
+ }
+ if (!strcmp(str, "Connection: close"))
+ {
+ cx->cclose = 1;
+ return;
+ }
+}
+
+static void process_byte(struct http_ctx *cx, char ch)
+{
+ if (cx->rxtogo)
+ {
+ cx->rxtogo--;
+
+ if (!cx->rbuf)
+ {
+ cx->rbuf = (char *)malloc(256);
+ cx->rlen = 256;
+ }
+ if (cx->rptr >= cx->rlen-1)
+ {
+ cx->rlen *= 2;
+ cx->rbuf = (char *)realloc(cx->rbuf, cx->rlen);
+ }
+ cx->rbuf[cx->rptr++] = ch;
+
+ if (!cx->rxtogo && !cx->chunked)
+ cx->state = HTS_DONE;
+ }
+ else
+ {
+ if (ch == '\n')
+ {
+ cx->hbuf[cx->hptr] = 0;
+ process_header(cx, cx->hbuf);
+ cx->hptr = 0;
+ }
+ else if (ch != '\r')
+ {
+ if (cx->hptr >= cx->hlen-1)
+ {
+ cx->hlen *= 2;
+ cx->hbuf = (char *)realloc(cx->hbuf, cx->hlen);
+ }
+ cx->hbuf[cx->hptr++] = ch;
+ }
+ }
+}
+
+int http_async_req_status(void *ctx)
+{
+ struct http_ctx *cx = (http_ctx *)ctx;
+ char *dns,*srv,buf[CHUNK];
+ int tmp, i;
+ time_t now = time(NULL);
+#ifdef WIN32
+ unsigned long tmp2;
+#endif
+
+ switch (cx->state)
+ {
+ case HTS_STRT:
+ dns = getserv(cx->host);
+ srv = getport(cx->host);
+ if (resolve(dns, srv, &cx->addr))
+ {
+ free(dns);
+ free(srv);
+ cx->state = HTS_DONE;
+ cx->ret = 602;
+ return 1;
+ }
+ free(dns);
+ free(srv);
+ cx->state = HTS_RSLV;
+ return 0;
+ case HTS_RSLV:
+ cx->state = HTS_CONN;
+ cx->last = now;
+ return 0;
+ case HTS_CONN:
+ if (cx->fd == PERROR)
+ {
+ cx->fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (cx->fd == PERROR)
+ goto fail;
+ cx->fdhost = mystrdup(cx->host);
+#ifdef WIN32
+ tmp2 = 1;
+ if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR)
+ goto fail;
+#else
+ tmp = fcntl(cx->fd, F_GETFL);
+ if (tmp < 0)
+ goto fail;
+ if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0)
+ goto fail;
+#endif
+ }
+ if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr)))
+ cx->state = HTS_IDLE;
+#ifdef WIN32
+ else if (PERRNO==WSAEISCONN)
+ cx->state = HTS_IDLE;
+#endif
+#ifdef MACOSX
+ else if (PERRNO==EISCONN)
+ cx->state = HTS_IDLE;
+#endif
+ else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY
+#ifdef WIN32
+ && PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL
+#endif
+ )
+ goto fail;
+ if (now-cx->last>http_timeout)
+ goto timeout;
+ return 0;
+ case HTS_IDLE:
+ if (cx->txdl)
+ {
+ // generate POST
+ cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 121 + cx->txdl + cx->thlen);
+ cx->tptr = 0;
+ cx->tlen = 0;
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path);
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host);
+ if (!cx->keep)
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n");
+ if (cx->thdr)
+ {
+ memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
+ cx->tlen += cx->thlen;
+ free(cx->thdr);
+ cx->thdr = NULL;
+ cx->thlen = 0;
+ }
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl);
+#ifdef BETA
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
+#else
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
+#endif
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n");
+ memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
+ cx->tlen += cx->txdl;
+ free(cx->txd);
+ cx->txd = NULL;
+ cx->txdl = 0;
+ }
+ else
+ {
+ // generate GET
+ cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 89 + cx->thlen);
+ cx->tptr = 0;
+ cx->tlen = 0;
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path);
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host);
+ if (cx->thdr)
+ {
+ memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
+ cx->tlen += cx->thlen;
+ free(cx->thdr);
+ cx->thdr = NULL;
+ cx->thlen = 0;
+ }
+ if (!cx->keep)
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n");
+#ifdef BETA
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
+#else
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
+#endif
+ cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n");
+ }
+ cx->state = HTS_XMIT;
+ cx->last = now;
+ return 0;
+ case HTS_XMIT:
+ tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0);
+ if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
+ goto fail;
+ if (tmp!=PERROR)
+ {
+ cx->tptr += tmp;
+ if (cx->tptr == cx->tlen)
+ {
+ cx->tptr = 0;
+ cx->tlen = 0;
+ if (cx->tbuf)
+ free(cx->tbuf);
+ cx->state = HTS_RECV;
+ }
+ cx->last = now;
+ }
+ if (now-cx->last>http_timeout)
+ goto timeout;
+ return 0;
+ case HTS_RECV:
+ tmp = recv(cx->fd, buf, CHUNK, 0);
+ if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
+ goto fail;
+ if (tmp!=PERROR)
+ {
+ for (i=0; i<tmp; i++)
+ {
+ process_byte(cx, buf[i]);
+ if (cx->state == HTS_DONE)
+ return 1;
+ }
+ cx->last = now;
+ }
+ if (now-cx->last>http_timeout)
+ goto timeout;
+ return 0;
+ case HTS_DONE:
+ return 1;
+ }
+ return 0;
+
+fail:
+ cx->ret = 600;
+ cx->state = HTS_DONE;
+ return 1;
+
+timeout:
+ cx->ret = 605;
+ cx->state = HTS_DONE;
+ return 1;
+}
+
+char *http_async_req_stop(void *ctx, int *ret, int *len)
+{
+ struct http_ctx *cx = (http_ctx *)ctx;
+ char *rxd;
+
+ if (cx->state != HTS_DONE)
+ while (!http_async_req_status(ctx)) ;
+
+ if (cx->host)
+ {
+ free(cx->host);
+ cx->host = NULL;
+ }
+ if (cx->path)
+ {
+ free(cx->path);
+ cx->path = NULL;
+ }
+ if (cx->txd)
+ {
+ free(cx->txd);
+ cx->txd = NULL;
+ cx->txdl = 0;
+ }
+ if (cx->hbuf)
+ {
+ free(cx->hbuf);
+ cx->hbuf = NULL;
+ }
+ if (cx->thdr)
+ {
+ free(cx->thdr);
+ cx->thdr = NULL;
+ cx->thlen = 0;
+ }
+
+ if (ret)
+ *ret = cx->ret;
+ if (len)
+ *len = cx->rptr;
+ if (cx->rbuf)
+ cx->rbuf[cx->rptr] = 0;
+ rxd = cx->rbuf;
+ cx->rbuf = NULL;
+ cx->rlen = 0;
+ cx->rptr = 0;
+ cx->contlen = 0;
+
+ if (!cx->keep)
+ http_async_req_close(ctx);
+ else if (cx->cclose)
+ {
+ PCLOSE(cx->fd);
+ cx->fd = PERROR;
+ if (cx->fdhost)
+ {
+ free(cx->fdhost);
+ cx->fdhost = NULL;
+ }
+ cx->state = HTS_STRT;
+ }
+ else
+ cx->state = HTS_IDLE;
+
+ return rxd;
+}
+
+void http_async_get_length(void *ctx, int *total, int *done)
+{
+ struct http_ctx *cx = (http_ctx *)ctx;
+ if (done)
+ *done = cx->rptr;
+ if (total)
+ *total = cx->contlen;
+}
+
+void http_async_req_close(void *ctx)
+{
+ struct http_ctx *cx = (http_ctx *)ctx;
+ void *tmp;
+ if (cx->host)
+ {
+ cx->keep = 1;
+ tmp = http_async_req_stop(ctx, NULL, NULL);
+ if (tmp)
+ free(tmp);
+ }
+ if (cx->fdhost)
+ free(cx->fdhost);
+ PCLOSE(cx->fd);
+ free(ctx);
+}
+
+char *http_simple_get(char *uri, int *ret, int *len)
+{
+ void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0);
+ if (!ctx)
+ {
+ if (ret)
+ *ret = 600;
+ if (len)
+ *len = 0;
+ return NULL;
+ }
+ return http_async_req_stop(ctx, ret, len);
+}
+static char hex[] = "0123456789abcdef";
+void http_auth_headers(void *ctx, char *user, char *pass, char *session_id)
+{
+ char *tmp;
+ int i;
+ unsigned char hash[16];
+ unsigned int m;
+ struct md5_context md5;
+
+ if (user)
+ {
+ if (pass)
+ {
+ md5_init(&md5);
+ md5_update(&md5, (unsigned char *)user, strlen(user));
+ md5_update(&md5, (unsigned char *)"-", 1);
+ m = 0;
+
+ md5_update(&md5, (unsigned char *)pass, strlen(pass));
+ md5_final(hash, &md5);
+ tmp = (char *)malloc(33);
+ for (i=0; i<16; i++)
+ {
+ tmp[i*2] = hex[hash[i]>>4];
+ tmp[i*2+1] = hex[hash[i]&15];
+ }
+ tmp[32] = 0;
+ http_async_add_header(ctx, "X-Auth-Hash", tmp);
+ free(tmp);
+ }
+ if (session_id)
+ {
+ http_async_add_header(ctx, "X-Auth-User-Id", user);
+ http_async_add_header(ctx, "X-Auth-Session-Key", session_id);
+ }
+ else
+ {
+ http_async_add_header(ctx, "X-Auth-User", user);
+ }
+ }
+}
+char *http_auth_get(char *uri, char *user, char *pass, char *session_id, int *ret, int *len)
+{
+ void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0);
+
+ if (!ctx)
+ {
+ if (ret)
+ *ret = 600;
+ if (len)
+ *len = 0;
+ return NULL;
+ }
+ return http_async_req_stop(ctx, ret, len);
+}
+
+char *http_simple_post(char *uri, char *data, int dlen, int *ret, int *len)
+{
+ void *ctx = http_async_req_start(NULL, uri, data, dlen, 0);
+ if (!ctx)
+ {
+ if (ret)
+ *ret = 600;
+ if (len)
+ *len = 0;
+ return NULL;
+ }
+ return http_async_req_stop(ctx, ret, len);
+}
+
+char *http_ret_text(int ret)
+{
+ switch (ret)
+ {
+ case 100:
+ return "Continue";
+ case 101:
+ return "Switching Protocols";
+ case 102:
+ return "Processing";
+
+ case 200:
+ return "OK";
+ case 201:
+ return "Created";
+ case 202:
+ return "Accepted";
+ case 203:
+ return "Non-Authoritative Information";
+ case 204:
+ return "No Content";
+ case 205:
+ return "Reset Content";
+ case 206:
+ return "Partial Content";
+ case 207:
+ return "Multi-Status";
+
+ case 300:
+ return "Multiple Choices";
+ case 301:
+ return "Moved Permanently";
+ case 302:
+ return "Found";
+ case 303:
+ return "See Other";
+ case 304:
+ return "Not Modified";
+ case 305:
+ return "Use Proxy";
+ case 306:
+ return "Switch Proxy";
+ case 307:
+ return "Temporary Redirect";
+
+ case 400:
+ return "Bad Request";
+ case 401:
+ return "Unauthorized";
+ case 402:
+ return "Payment Required";
+ case 403:
+ return "Forbidden";
+ case 404:
+ return "Not Found";
+ case 405:
+ return "Method Not Allowed";
+ case 406:
+ return "Not Acceptable";
+ case 407:
+ return "Proxy Authentication Required";
+ case 408:
+ return "Request Timeout";
+ case 409:
+ return "Conflict";
+ case 410:
+ return "Gone";
+ case 411:
+ return "Length Required";
+ case 412:
+ return "Precondition Failed";
+ case 413:
+ return "Request Entity Too Large";
+ case 414:
+ return "Request URI Too Long";
+ case 415:
+ return "Unsupported Media Type";
+ case 416:
+ return "Requested Range Not Satisfiable";
+ case 417:
+ return "Expectation Failed";
+ case 418:
+ return "I'm a teapot";
+ case 422:
+ return "Unprocessable Entity";
+ case 423:
+ return "Locked";
+ case 424:
+ return "Failed Dependency";
+ case 425:
+ return "Unordered Collection";
+ case 426:
+ return "Upgrade Required";
+ case 444:
+ return "No Response";
+ case 450:
+ return "Blocked by Windows Parental Controls";
+ case 499:
+ return "Client Closed Request";
+
+ case 500:
+ return "Internal Server Error";
+ case 501:
+ return "Not Implemented";
+ case 502:
+ return "Bad Gateway";
+ case 503:
+ return "Service Unavailable";
+ case 504:
+ return "Gateway Timeout";
+ case 505:
+ return "HTTP Version Not Supported";
+ case 506:
+ return "Variant Also Negotiates";
+ case 507:
+ return "Insufficient Storage";
+ case 509:
+ return "Bandwidth Limit Exceeded";
+ case 510:
+ return "Not Extended";
+
+ case 600:
+ return "Internal Client Error";
+ case 601:
+ return "Unsupported Protocol";
+ case 602:
+ return "Server Not Found";
+ case 603:
+ return "Malformed Response";
+ case 604:
+ return "Network Not Available";
+ case 605:
+ return "Request Timed Out";
+ default:
+ return "Unknown Status Code";
+ }
+}
+char *http_multipart_post(char *uri, char **names, char **parts, int *plens, char *user, char *pass, char *session_id, int *ret, int *len)
+{
+ void *ctx;
+ char *data = NULL, *tmp, *p;
+ int dlen = 0, i, j;
+ unsigned char hash[16];
+ unsigned char boundary[32], ch;
+ int blen = 0;
+ unsigned int map[62], m;
+ struct md5_context md5;
+ //struct md5_context md52;
+ int own_plen = 0;
+
+ if (names)
+ {
+ if (!plens)
+ {
+ own_plen = 1;
+ for (i=0; names[i]; i++) ;
+ plens = (int *)calloc(i, sizeof(int));
+ for (i=0; names[i]; i++)
+ plens[i] = strlen(parts[i]);
+ }
+
+retry:
+ if (blen >= 31)
+ goto fail;
+ memset(map, 0, 62*sizeof(int));
+ for (i=0; names[i]; i++)
+ {
+ for (j=0; j<plens[i]-blen; j++)
+ if (!blen || !memcmp(parts[i]+j, boundary, blen))
+ {
+ ch = parts[i][j+blen];
+ if (ch>='0' && ch<='9')
+ map[ch-'0']++;
+ else if (ch>='A' && ch<='Z')
+ map[ch-'A'+10]++;
+ else if (ch>='a' && ch<='z')
+ map[ch-'a'+36]++;
+ }
+ }
+ m = ~0;
+ j = 61;
+ for (i=0; i<62; i++)
+ if (map[i]<m)
+ {
+ m = map[i];
+ j = i;
+ }
+ if (j<10)
+ boundary[blen] = '0'+j;
+ else if (j<36)
+ boundary[blen] = 'A'+(j-10);
+ else
+ boundary[blen] = 'a'+(j-36);
+ blen++;
+ if (map[j])
+ goto retry;
+ boundary[blen] = 0;
+
+ for (i=0; names[i]; i++)
+ dlen += blen+strlen(names[i])+plens[i]+128;
+ dlen += blen+8;
+ data = (char *)malloc(dlen);
+ dlen = 0;
+ for (i=0; names[i]; i++)
+ {
+ dlen += sprintf(data+dlen, "--%s\r\n", boundary);
+ dlen += sprintf(data+dlen, "Content-transfer-encoding: binary\r\n");
+ if (strchr(names[i], ':'))
+ {
+ tmp = mystrdup(names[i]);
+ p = strchr(tmp, ':');
+ *p = 0;
+ dlen += sprintf(data+dlen, "content-disposition: form-data; name=\"%s\"; ", tmp);
+ free(tmp);
+ p = strchr(names[i], ':');
+ dlen += sprintf(data+dlen, "filename=\"%s\"\r\n\r\n", p+1);
+ }
+ else
+ dlen += sprintf(data+dlen, "content-disposition: form-data; name=\"%s\"\r\n\r\n", names[i]);
+ memcpy(data+dlen, parts[i], plens[i]);
+ dlen += plens[i];
+ dlen += sprintf(data+dlen, "\r\n");
+ }
+ dlen += sprintf(data+dlen, "--%s--\r\n", boundary);
+ }
+
+ ctx = http_async_req_start(NULL, uri, data, dlen, 0);
+ if (!ctx)
+ goto fail;
+
+ if (user)
+ {
+ //http_async_add_header(ctx, "X-Auth-User", user);
+ if (pass)
+ {
+ md5_init(&md5);
+ md5_update(&md5, (unsigned char *)user, strlen(user));
+ md5_update(&md5, (unsigned char *)"-", 1);
+ m = 0;
+ if (names)
+ {
+ for (i=0; names[i]; i++)
+ {
+ //md5_update(&md5, (unsigned char *)parts[i], plens[i]); //WHY?
+ //md5_update(&md5, (unsigned char *)"-", 1);
+ p = strchr(names[i], ':');
+ if (p)
+ m += (p - names[i]) + 1;
+ else
+ m += strlen(names[i])+1;
+ }
+
+ tmp = (char *)malloc(m);
+ m = 0;
+ for (i=0; names[i]; i++)
+ {
+ p = strchr(names[i], ':');
+ if (m)
+ {
+ tmp[m] = ' ';
+ m ++;
+ }
+ if (p)
+ {
+ memcpy(tmp+m, names[i], p-names[i]);
+ m += p - names[i];
+ }
+ else
+ {
+ strcpy(tmp+m, names[i]);
+ m += strlen(names[i]);
+ }
+ }
+ tmp[m] = 0;
+ http_async_add_header(ctx, "X-Auth-Objects", tmp);
+ free(tmp);
+ }
+
+ md5_update(&md5, (unsigned char *)pass, strlen(pass));
+ md5_final(hash, &md5);
+ tmp = (char *)malloc(33);
+ for (i=0; i<16; i++)
+ {
+ tmp[i*2] = hex[hash[i]>>4];
+ tmp[i*2+1] = hex[hash[i]&15];
+ }
+ tmp[32] = 0;
+ http_async_add_header(ctx, "X-Auth-Hash", tmp);
+ free(tmp);
+ }
+ if (session_id)
+ {
+ http_async_add_header(ctx, "X-Auth-User-Id", user);
+ http_async_add_header(ctx, "X-Auth-Session-Key", session_id);
+ }
+ else
+ {
+ http_async_add_header(ctx, "X-Auth-User", user);
+ }
+ }
+
+ if (data)
+ {
+ tmp = (char *)malloc(32+strlen((char *)boundary));
+ sprintf(tmp, "multipart/form-data, boundary=%s", boundary);
+ http_async_add_header(ctx, "Content-type", tmp);
+ free(tmp);
+ free(data);
+ }
+
+ if (own_plen)
+ free(plens);
+ return http_async_req_stop(ctx, ret, len);
+
+fail:
+ if (data)
+ free(data);
+ if (own_plen)
+ free(plens);
+ if (ret)
+ *ret = 600;
+ if (len)
+ *len = 0;
+ return NULL;
+}
diff --git a/src/client/HTTP.h b/src/client/HTTP.h
new file mode 100644
index 0000000..af0971c
--- /dev/null
+++ b/src/client/HTTP.h
@@ -0,0 +1,43 @@
+/**
+ * Powder Toy - HTTP Library (Header)
+ *
+ * Copyright (c) 2008 - 2010 Stanislaw Skowronek.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+#ifndef HTTP_H
+#define HTTP_H
+
+void http_init(char *proxy);
+void http_done(void);
+
+char *http_simple_get(char *uri, int *ret, int *len);
+char *http_auth_get(char *uri, char *user, char *pass, char * session_id, int *ret, int *len);
+char *http_simple_post(char *uri, char *data, int dlen, int *ret, int *len);
+
+void http_auth_headers(void *ctx, char *user, char *pass, char * session_id);
+
+void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep);
+void http_async_add_header(void *ctx, char *name, char *data);
+int http_async_req_status(void *ctx);
+void http_async_get_length(void *ctx, int *total, int *done);
+char *http_async_req_stop(void *ctx, int *ret, int *len);
+void http_async_req_close(void *ctx);
+
+char *http_multipart_post(char *uri, char **names, char **parts, int *plens, char *user, char *pass, char * session_id, int *ret, int *len);
+
+char *http_ret_text(int ret);
+
+#endif
diff --git a/src/client/MD5.cpp b/src/client/MD5.cpp
new file mode 100644
index 0000000..9cb398c
--- /dev/null
+++ b/src/client/MD5.cpp
@@ -0,0 +1,231 @@
+// based on public-domain code from Colin Plumb (1993)
+#include <string.h>
+#include "MD5.h"
+
+static unsigned getu32(const unsigned char *addr)
+{
+ return (((((unsigned long)addr[3] << 8) | addr[2]) << 8) | addr[1]) << 8 | addr[0];
+}
+
+static void putu32(unsigned data, unsigned char *addr)
+{
+ addr[0] = (unsigned char)data;
+ addr[1] = (unsigned char)(data >> 8);
+ addr[2] = (unsigned char)(data >> 16);
+ addr[3] = (unsigned char)(data >> 24);
+}
+
+void md5_init(struct md5_context *ctx)
+{
+ ctx->buf[0] = 0x67452301;
+ ctx->buf[1] = 0xefcdab89;
+ ctx->buf[2] = 0x98badcfe;
+ ctx->buf[3] = 0x10325476;
+
+ ctx->bits[0] = 0;
+ ctx->bits[1] = 0;
+}
+
+void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
+{
+ unsigned t;
+
+ // update bit count
+ t = ctx->bits[0];
+ if ((ctx->bits[0] = (t + ((unsigned)len << 3)) & 0xffffffff) < t)
+ ctx->bits[1]++; // carry
+ ctx->bits[1] += len >> 29;
+
+ t = (t >> 3) & 0x3f;
+
+ // use leading data to top up the buffer
+
+ if (t)
+ {
+ unsigned char *p = ctx->in + t;
+
+ t = 64-t;
+ if (len < t)
+ {
+ memcpy(p, buf, len);
+ return;
+ }
+ memcpy(p, buf, t);
+ md5_transform(ctx->buf, ctx->in);
+ buf += t;
+ len -= t;
+ }
+
+ // following 64-byte chunks
+
+ while (len >= 64)
+ {
+ memcpy(ctx->in, buf, 64);
+ md5_transform(ctx->buf, ctx->in);
+ buf += 64;
+ len -= 64;
+ }
+
+ // save rest of bytes for later
+
+ memcpy(ctx->in, buf, len);
+}
+
+void md5_final(unsigned char digest[16], struct md5_context *ctx)
+{
+ unsigned count;
+ unsigned char *p;
+
+ // #bytes mod64
+ count = (ctx->bits[0] >> 3) & 0x3F;
+
+ // first char of padding = 0x80
+ p = ctx->in + count;
+ *p++ = 0x80;
+
+ // calculate # of bytes to pad
+ count = 64 - 1 - count;
+
+ // Pad out to 56 mod 64
+ if (count < 8)
+ {
+ // we need to finish a whole block before padding
+ memset(p, 0, count);
+ md5_transform(ctx->buf, ctx->in);
+ memset(ctx->in, 0, 56);
+ }
+ else
+ {
+ // just pad to 56 bytes
+ memset(p, 0, count-8);
+ }
+
+ // append length & final transform
+ putu32(ctx->bits[0], ctx->in + 56);
+ putu32(ctx->bits[1], ctx->in + 60);
+
+ md5_transform(ctx->buf, ctx->in);
+ putu32(ctx->buf[0], digest);
+ putu32(ctx->buf[1], digest + 4);
+ putu32(ctx->buf[2], digest + 8);
+ putu32(ctx->buf[3], digest + 12);
+ memset(ctx, 0, sizeof(ctx));
+}
+
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+#define MD5STEP(f, w, x, y, z, data, s) \
+ ( w += f(x, y, z) + data, w &= 0xffffffff, w = w<<s | w>>(32-s), w += x )
+
+void md5_transform(unsigned buf[4], const unsigned char inraw[64])
+{
+ unsigned a, b, c, d;
+ unsigned in[16];
+ int i;
+
+ for (i = 0; i < 16; ++i)
+ in[i] = getu32 (inraw + 4 * i);
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ MD5STEP(F1, a, b, c, d, in[ 0]+0xd76aa478, 7);
+ MD5STEP(F1, d, a, b, c, in[ 1]+0xe8c7b756, 12);
+ MD5STEP(F1, c, d, a, b, in[ 2]+0x242070db, 17);
+ MD5STEP(F1, b, c, d, a, in[ 3]+0xc1bdceee, 22);
+ MD5STEP(F1, a, b, c, d, in[ 4]+0xf57c0faf, 7);
+ MD5STEP(F1, d, a, b, c, in[ 5]+0x4787c62a, 12);
+ MD5STEP(F1, c, d, a, b, in[ 6]+0xa8304613, 17);
+ MD5STEP(F1, b, c, d, a, in[ 7]+0xfd469501, 22);
+ MD5STEP(F1, a, b, c, d, in[ 8]+0x698098d8, 7);
+ MD5STEP(F1, d, a, b, c, in[ 9]+0x8b44f7af, 12);
+ MD5STEP(F1, c, d, a, b, in[10]+0xffff5bb1, 17);
+ MD5STEP(F1, b, c, d, a, in[11]+0x895cd7be, 22);
+ MD5STEP(F1, a, b, c, d, in[12]+0x6b901122, 7);
+ MD5STEP(F1, d, a, b, c, in[13]+0xfd987193, 12);
+ MD5STEP(F1, c, d, a, b, in[14]+0xa679438e, 17);
+ MD5STEP(F1, b, c, d, a, in[15]+0x49b40821, 22);
+
+ MD5STEP(F2, a, b, c, d, in[ 1]+0xf61e2562, 5);
+ MD5STEP(F2, d, a, b, c, in[ 6]+0xc040b340, 9);
+ MD5STEP(F2, c, d, a, b, in[11]+0x265e5a51, 14);
+ MD5STEP(F2, b, c, d, a, in[ 0]+0xe9b6c7aa, 20);
+ MD5STEP(F2, a, b, c, d, in[ 5]+0xd62f105d, 5);
+ MD5STEP(F2, d, a, b, c, in[10]+0x02441453, 9);
+ MD5STEP(F2, c, d, a, b, in[15]+0xd8a1e681, 14);
+ MD5STEP(F2, b, c, d, a, in[ 4]+0xe7d3fbc8, 20);
+ MD5STEP(F2, a, b, c, d, in[ 9]+0x21e1cde6, 5);
+ MD5STEP(F2, d, a, b, c, in[14]+0xc33707d6, 9);
+ MD5STEP(F2, c, d, a, b, in[ 3]+0xf4d50d87, 14);
+ MD5STEP(F2, b, c, d, a, in[ 8]+0x455a14ed, 20);
+ MD5STEP(F2, a, b, c, d, in[13]+0xa9e3e905, 5);
+ MD5STEP(F2, d, a, b, c, in[ 2]+0xfcefa3f8, 9);
+ MD5STEP(F2, c, d, a, b, in[ 7]+0x676f02d9, 14);
+ MD5STEP(F2, b, c, d, a, in[12]+0x8d2a4c8a, 20);
+
+ MD5STEP(F3, a, b, c, d, in[ 5]+0xfffa3942, 4);
+ MD5STEP(F3, d, a, b, c, in[ 8]+0x8771f681, 11);
+ MD5STEP(F3, c, d, a, b, in[11]+0x6d9d6122, 16);
+ MD5STEP(F3, b, c, d, a, in[14]+0xfde5380c, 23);
+ MD5STEP(F3, a, b, c, d, in[ 1]+0xa4beea44, 4);
+ MD5STEP(F3, d, a, b, c, in[ 4]+0x4bdecfa9, 11);
+ MD5STEP(F3, c, d, a, b, in[ 7]+0xf6bb4b60, 16);
+ MD5STEP(F3, b, c, d, a, in[10]+0xbebfbc70, 23);
+ MD5STEP(F3, a, b, c, d, in[13]+0x289b7ec6, 4);
+ MD5STEP(F3, d, a, b, c, in[ 0]+0xeaa127fa, 11);
+ MD5STEP(F3, c, d, a, b, in[ 3]+0xd4ef3085, 16);
+ MD5STEP(F3, b, c, d, a, in[ 6]+0x04881d05, 23);
+ MD5STEP(F3, a, b, c, d, in[ 9]+0xd9d4d039, 4);
+ MD5STEP(F3, d, a, b, c, in[12]+0xe6db99e5, 11);
+ MD5STEP(F3, c, d, a, b, in[15]+0x1fa27cf8, 16);
+ MD5STEP(F3, b, c, d, a, in[ 2]+0xc4ac5665, 23);
+
+ MD5STEP(F4, a, b, c, d, in[ 0]+0xf4292244, 6);
+ MD5STEP(F4, d, a, b, c, in[ 7]+0x432aff97, 10);
+ MD5STEP(F4, c, d, a, b, in[14]+0xab9423a7, 15);
+ MD5STEP(F4, b, c, d, a, in[ 5]+0xfc93a039, 21);
+ MD5STEP(F4, a, b, c, d, in[12]+0x655b59c3, 6);
+ MD5STEP(F4, d, a, b, c, in[ 3]+0x8f0ccc92, 10);
+ MD5STEP(F4, c, d, a, b, in[10]+0xffeff47d, 15);
+ MD5STEP(F4, b, c, d, a, in[ 1]+0x85845dd1, 21);
+ MD5STEP(F4, a, b, c, d, in[ 8]+0x6fa87e4f, 6);
+ MD5STEP(F4, d, a, b, c, in[15]+0xfe2ce6e0, 10);
+ MD5STEP(F4, c, d, a, b, in[ 6]+0xa3014314, 15);
+ MD5STEP(F4, b, c, d, a, in[13]+0x4e0811a1, 21);
+ MD5STEP(F4, a, b, c, d, in[ 4]+0xf7537e82, 6);
+ MD5STEP(F4, d, a, b, c, in[11]+0xbd3af235, 10);
+ MD5STEP(F4, c, d, a, b, in[ 2]+0x2ad7d2bb, 15);
+ MD5STEP(F4, b, c, d, a, in[ 9]+0xeb86d391, 21);
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
+
+static char hex[] = "0123456789abcdef";
+void md5_ascii(char *result, unsigned char const *buf, unsigned len)
+{
+ struct md5_context md5;
+ unsigned char hash[16];
+ int i;
+
+ if (len==0)
+ len = strlen((char *)buf);
+
+ md5_init(&md5);
+ md5_update(&md5, buf, len);
+ md5_final(hash, &md5);
+
+ for (i=0; i<16; i++)
+ {
+ result[i*2] = hex[(hash[i]>>4)&0xF];
+ result[i*2+1] = hex[hash[i]&0x0F];
+ }
+ result[32] = 0;
+}
diff --git a/src/client/MD5.h b/src/client/MD5.h
new file mode 100644
index 0000000..a8ef123
--- /dev/null
+++ b/src/client/MD5.h
@@ -0,0 +1,18 @@
+#ifndef MD5_H
+#define MD5_H
+
+struct md5_context
+{
+ unsigned buf[4];
+ unsigned bits[2];
+ unsigned char in[64];
+};
+
+void md5_init(struct md5_context *context);
+void md5_update(struct md5_context *context, unsigned char const *buf, unsigned len);
+void md5_final(unsigned char digest[16], struct md5_context *context);
+void md5_transform(unsigned buf[4], const unsigned char in[64]);
+
+void md5_ascii(char *result, unsigned char const *buf, unsigned len);
+
+#endif
diff --git a/src/elements/O2.cpp b/src/elements/O2.cpp
index 78b4229..864d9e8 100644
--- a/src/elements/O2.cpp
+++ b/src/elements/O2.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_O2(UPDATE_FUNC_ARGS)
{
diff --git a/src/elements/acel.cpp b/src/elements/acel.cpp
index 7ab9684..0d69894 100644
--- a/src/elements/acel.cpp
+++ b/src/elements/acel.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_ACEL(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/acid.cpp b/src/elements/acid.cpp
index 3a72b9d..8d881fd 100644
--- a/src/elements/acid.cpp
+++ b/src/elements/acid.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_ACID(UPDATE_FUNC_ARGS) {
int r, rx, ry, trade, np;
diff --git a/src/elements/amtr.cpp b/src/elements/amtr.cpp
index d119cc9..5ff4529 100644
--- a/src/elements/amtr.cpp
+++ b/src/elements/amtr.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_AMTR(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/anar.cpp b/src/elements/anar.cpp
index 83eaf5a..6db0d2e 100644
--- a/src/elements/anar.cpp
+++ b/src/elements/anar.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_ANAR(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/aray.cpp b/src/elements/aray.cpp
index 65b0d53..2ab9b40 100644
--- a/src/elements/aray.cpp
+++ b/src/elements/aray.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_ARAY(UPDATE_FUNC_ARGS) {
int r, nxx, nyy, docontinue, nxi, nyi, rx, ry, nr, ry1, rx1;
diff --git a/src/elements/bang.cpp b/src/elements/bang.cpp
index 658a567..7a1f673 100644
--- a/src/elements/bang.cpp
+++ b/src/elements/bang.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BANG(UPDATE_FUNC_ARGS) {
int r, rx, ry, nb;
diff --git a/src/elements/bcln.cpp b/src/elements/bcln.cpp
index 8c00f95..702b322 100644
--- a/src/elements/bcln.cpp
+++ b/src/elements/bcln.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BCLN(UPDATE_FUNC_ARGS) {
if (!parts[i].life && sim->pv[y/CELL][x/CELL]>4.0f)
diff --git a/src/elements/bcol.cpp b/src/elements/bcol.cpp
index d941508..d727abf 100644
--- a/src/elements/bcol.cpp
+++ b/src/elements/bcol.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BCOL(UPDATE_FUNC_ARGS) {
int r, rx, ry, trade, temp;
diff --git a/src/elements/bizr.cpp b/src/elements/bizr.cpp
index 538b87f..aae09d9 100644
--- a/src/elements/bizr.cpp
+++ b/src/elements/bizr.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
//Used by ALL 3 BIZR states
int update_BIZR(UPDATE_FUNC_ARGS) {
diff --git a/src/elements/bmtl.cpp b/src/elements/bmtl.cpp
index a3dc4b8..8682561 100644
--- a/src/elements/bmtl.cpp
+++ b/src/elements/bmtl.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BMTL(UPDATE_FUNC_ARGS) {
int r, rx, ry, rt, tempFactor;
diff --git a/src/elements/bomb.cpp b/src/elements/bomb.cpp
index b2e9e7d..b696b19 100644
--- a/src/elements/bomb.cpp
+++ b/src/elements/bomb.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BOMB(UPDATE_FUNC_ARGS) {
int r, rx, ry, nb;
diff --git a/src/elements/boyl.cpp b/src/elements/boyl.cpp
index e4ee6d2..7c0fc24 100644
--- a/src/elements/boyl.cpp
+++ b/src/elements/boyl.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BOYL(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/brmt.cpp b/src/elements/brmt.cpp
index c23bd99..0e49cd1 100644
--- a/src/elements/brmt.cpp
+++ b/src/elements/brmt.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BRMT(UPDATE_FUNC_ARGS) {
int r, rx, ry, rt, tempFactor;
diff --git a/src/elements/btry.cpp b/src/elements/btry.cpp
index 3f11003..0168e08 100644
--- a/src/elements/btry.cpp
+++ b/src/elements/btry.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_BTRY(UPDATE_FUNC_ARGS) {
int r, rx, ry, rt;
diff --git a/src/elements/c5.cpp b/src/elements/c5.cpp
index 412245f..8a10915 100644
--- a/src/elements/c5.cpp
+++ b/src/elements/c5.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_C5(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/caus.cpp b/src/elements/caus.cpp
index 2ec268e..fb71969 100644
--- a/src/elements/caus.cpp
+++ b/src/elements/caus.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_CAUS(UPDATE_FUNC_ARGS) {
int r, rx, ry, trade, np;
diff --git a/src/elements/cbnw.cpp b/src/elements/cbnw.cpp
index cf0c13e..37625b0 100644
--- a/src/elements/cbnw.cpp
+++ b/src/elements/cbnw.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_CBNW(UPDATE_FUNC_ARGS) {
int r, rx, ry, oldt;
diff --git a/src/elements/clne.cpp b/src/elements/clne.cpp
index 13b25b9..303908e 100644
--- a/src/elements/clne.cpp
+++ b/src/elements/clne.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_CLNE(UPDATE_FUNC_ARGS) {
if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
diff --git a/src/elements/clst.cpp b/src/elements/clst.cpp
index 2c31d87..f8653be 100644
--- a/src/elements/clst.cpp
+++ b/src/elements/clst.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_CLST(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/co2.cpp b/src/elements/co2.cpp
index 5a3bbf5..62bc646 100644
--- a/src/elements/co2.cpp
+++ b/src/elements/co2.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_CO2(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/coal.cpp b/src/elements/coal.cpp
index 256aa69..23d20ba 100644
--- a/src/elements/coal.cpp
+++ b/src/elements/coal.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_COAL(UPDATE_FUNC_ARGS) {
int r, rx, ry, trade, temp;
diff --git a/src/elements/conv.cpp b/src/elements/conv.cpp
index ce4ee48..a62cd55 100644
--- a/src/elements/conv.cpp
+++ b/src/elements/conv.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_CONV(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/dest.cpp b/src/elements/dest.cpp
index 014fad4..fa5faf8 100644
--- a/src/elements/dest.cpp
+++ b/src/elements/dest.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_DEST(UPDATE_FUNC_ARGS) {
int r,rx,ry,topv;
diff --git a/src/elements/deut.cpp b/src/elements/deut.cpp
index 03de364..cee38de 100644
--- a/src/elements/deut.cpp
+++ b/src/elements/deut.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_DEUT(UPDATE_FUNC_ARGS) {
int r, rx, ry, trade, np;
diff --git a/src/elements/dlay.cpp b/src/elements/dlay.cpp
index 4643b30..e40c362 100644
--- a/src/elements/dlay.cpp
+++ b/src/elements/dlay.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_DLAY(UPDATE_FUNC_ARGS) {
int r, rx, ry, oldl;
diff --git a/src/elements/dstw.cpp b/src/elements/dstw.cpp
index 03ae7dd..21d7db2 100644
--- a/src/elements/dstw.cpp
+++ b/src/elements/dstw.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_DSTW(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/elec.cpp b/src/elements/elec.cpp
index 6b06f8f..e8ddf5e 100644
--- a/src/elements/elec.cpp
+++ b/src/elements/elec.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_ELEC(UPDATE_FUNC_ARGS) {
int r, rt, rx, ry, nb, rrx, rry;
diff --git a/src/elements/elementmisc.cpp b/src/elements/elementmisc.cpp
index a169e80..4df53f4 100644
--- a/src/elements/elementmisc.cpp
+++ b/src/elements/elementmisc.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_MISC(UPDATE_FUNC_ARGS) {
/*int t = parts[i].type;
diff --git a/src/elements/emp.cpp b/src/elements/emp.cpp
index a187196..2b3db86 100644
--- a/src/elements/emp.cpp
+++ b/src/elements/emp.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_EMP(UPDATE_FUNC_ARGS) {
int r,rx,ry,ok=0,t,n,nx,ny;
diff --git a/src/elements/figh.cpp b/src/elements/figh.cpp
index 8b18871..35b5a20 100644
--- a/src/elements/figh.cpp
+++ b/src/elements/figh.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FIGH(UPDATE_FUNC_ARGS)
{
diff --git a/src/elements/fire.cpp b/src/elements/fire.cpp
index 1f9c0c2..3f36916 100644
--- a/src/elements/fire.cpp
+++ b/src/elements/fire.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int graphics_FIRE(GRAPHICS_FUNC_ARGS)
{
diff --git a/src/elements/firw.cpp b/src/elements/firw.cpp
index 74605b0..ffd7941 100644
--- a/src/elements/firw.cpp
+++ b/src/elements/firw.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FIRW(UPDATE_FUNC_ARGS) {
int r, rx, ry, rt, np;
diff --git a/src/elements/fog.cpp b/src/elements/fog.cpp
index 28952e9..24ea953 100644
--- a/src/elements/fog.cpp
+++ b/src/elements/fog.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FOG(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/frzw.cpp b/src/elements/frzw.cpp
index 932bccb..4569911 100644
--- a/src/elements/frzw.cpp
+++ b/src/elements/frzw.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FRZW(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/frzz.cpp b/src/elements/frzz.cpp
index 8e09c1d..b412cbc 100644
--- a/src/elements/frzz.cpp
+++ b/src/elements/frzz.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FRZZ(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/fsep.cpp b/src/elements/fsep.cpp
index 3db5ba5..347fc46 100644
--- a/src/elements/fsep.cpp
+++ b/src/elements/fsep.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FSEP(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/fuse.cpp b/src/elements/fuse.cpp
index e1db1ff..9081b21 100644
--- a/src/elements/fuse.cpp
+++ b/src/elements/fuse.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FUSE(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/fwrk.cpp b/src/elements/fwrk.cpp
index d217ad9..1838dde 100644
--- a/src/elements/fwrk.cpp
+++ b/src/elements/fwrk.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_FWRK(UPDATE_FUNC_ARGS) {
int r, rx, ry, np;
diff --git a/src/elements/gbmb.cpp b/src/elements/gbmb.cpp
index 95afc4e..d1d7c20 100644
--- a/src/elements/gbmb.cpp
+++ b/src/elements/gbmb.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_GBMB(UPDATE_FUNC_ARGS) {
int rx,ry,r;
if (parts[i].life<=0)
diff --git a/src/elements/glas.cpp b/src/elements/glas.cpp
index e8c0a6c..ef9e7f7 100644
--- a/src/elements/glas.cpp
+++ b/src/elements/glas.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_GLAS(UPDATE_FUNC_ARGS) {
parts[i].pavg[0] = parts[i].pavg[1];
diff --git a/src/elements/glow.cpp b/src/elements/glow.cpp
index e83e2f4..38f7140 100644
--- a/src/elements/glow.cpp
+++ b/src/elements/glow.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_GLOW(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/goo.cpp b/src/elements/goo.cpp
index c305182..6e66468 100644
--- a/src/elements/goo.cpp
+++ b/src/elements/goo.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_GOO(UPDATE_FUNC_ARGS) {
if (!parts[i].life && sim->pv[y/CELL][x/CELL]>1.0f)
diff --git a/src/elements/gpmp.cpp b/src/elements/gpmp.cpp
index dcde7a9..3ad552b 100644
--- a/src/elements/gpmp.cpp
+++ b/src/elements/gpmp.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_GPMP(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/graphics_default.cpp b/src/elements/graphics_default.cpp
index 1270977..cf394aa 100644
--- a/src/elements/graphics_default.cpp
+++ b/src/elements/graphics_default.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int graphics_DEFAULT(GRAPHICS_FUNC_ARGS)
{
diff --git a/src/elements/h2.cpp b/src/elements/h2.cpp
index da39ad0..3a92cfe 100644
--- a/src/elements/h2.cpp
+++ b/src/elements/h2.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_H2(UPDATE_FUNC_ARGS)
{
diff --git a/src/elements/hswc.cpp b/src/elements/hswc.cpp
index c727395..a279947 100644
--- a/src/elements/hswc.cpp
+++ b/src/elements/hswc.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_HSWC(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/ice.cpp b/src/elements/ice.cpp
index aece17b..aab4e0e 100644
--- a/src/elements/ice.cpp
+++ b/src/elements/ice.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_ICEI(UPDATE_FUNC_ARGS) { //currently used for snow as well
int r, rx, ry;
diff --git a/src/elements/ignt.cpp b/src/elements/ignt.cpp
index 1d7ea64..66b0e18 100644
--- a/src/elements/ignt.cpp
+++ b/src/elements/ignt.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_IGNT(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/iron.cpp b/src/elements/iron.cpp
index b887cf8..391b708 100644
--- a/src/elements/iron.cpp
+++ b/src/elements/iron.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_IRON(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/isz.cpp b/src/elements/isz.cpp
index 25446d2..22e6c77 100644
--- a/src/elements/isz.cpp
+++ b/src/elements/isz.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_ISZ(UPDATE_FUNC_ARGS) { // for both ISZS and ISOZ
float rr, rrr;
diff --git a/src/elements/lava.cpp b/src/elements/lava.cpp
index 3d7827b..cc0fbb3 100644
--- a/src/elements/lava.cpp
+++ b/src/elements/lava.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int graphics_LAVA(GRAPHICS_FUNC_ARGS)
{
diff --git a/src/elements/lcry.cpp b/src/elements/lcry.cpp
index 546c2ca..0ecb84c 100644
--- a/src/elements/lcry.cpp
+++ b/src/elements/lcry.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_LCRY(UPDATE_FUNC_ARGS)
{
diff --git a/src/elements/legacy.cpp b/src/elements/legacy.cpp
index dd58173..f1fcf03 100644
--- a/src/elements/legacy.cpp
+++ b/src/elements/legacy.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
// Interactions which only occur when legacy_enable is on
int update_legacy_all(UPDATE_FUNC_ARGS) {
diff --git a/src/elements/ligh.cpp b/src/elements/ligh.cpp
index 8108c4b..5249c4f 100644
--- a/src/elements/ligh.cpp
+++ b/src/elements/ligh.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
#define LIGHTING_POWER 0.65
diff --git a/src/elements/merc.cpp b/src/elements/merc.cpp
index 2df113b..58b19a3 100644
--- a/src/elements/merc.cpp
+++ b/src/elements/merc.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_MERC(UPDATE_FUNC_ARGS) {
int r, rx, ry, trade, np;
diff --git a/src/elements/mort.cpp b/src/elements/mort.cpp
index bbb6264..9de088f 100644
--- a/src/elements/mort.cpp
+++ b/src/elements/mort.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_MORT(UPDATE_FUNC_ARGS) {
sim->create_part(-1, x, y-1, PT_SMKE);
diff --git a/src/elements/nbhl.cpp b/src/elements/nbhl.cpp
index 056313c..565416f 100644
--- a/src/elements/nbhl.cpp
+++ b/src/elements/nbhl.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_NBHL(UPDATE_FUNC_ARGS) {
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += 0.1f;
diff --git a/src/elements/neut.cpp b/src/elements/neut.cpp
index a48fc09..c804106 100644
--- a/src/elements/neut.cpp
+++ b/src/elements/neut.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int create_n_parts(Simulation * sim, int n, int x, int y, float vx, float vy, float temp, int t)//testing a new deut create part
diff --git a/src/elements/newgraphics.cpp b/src/elements/newgraphics.cpp
index 83da27b..036a6a7 100644
--- a/src/elements/newgraphics.cpp
+++ b/src/elements/newgraphics.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
#include "hmap.h"
int graphics_QRTZ(GRAPHICS_FUNC_ARGS) //QRTZ and PQRT
diff --git a/src/elements/none.cpp b/src/elements/none.cpp
index 50f301f..6974e6c 100644
--- a/src/elements/none.cpp
+++ b/src/elements/none.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_(UPDATE_FUNC_ARGS) {
diff --git a/src/elements/nptct.cpp b/src/elements/nptct.cpp
index 2d68a9b..f8e29e6 100644
--- a/src/elements/nptct.cpp
+++ b/src/elements/nptct.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_NPTCT(UPDATE_FUNC_ARGS) {
if (parts[i].temp>295.0f)
diff --git a/src/elements/nwhl.cpp b/src/elements/nwhl.cpp
index f53b657..cae189a 100644
--- a/src/elements/nwhl.cpp
+++ b/src/elements/nwhl.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_NWHL(UPDATE_FUNC_ARGS) {
sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] -= 0.1f;
diff --git a/src/elements/pbcn.cpp b/src/elements/pbcn.cpp
index 7e99397..a6bbe5a 100644
--- a/src/elements/pbcn.cpp
+++ b/src/elements/pbcn.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PBCN(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/pcln.cpp b/src/elements/pcln.cpp
index cd1ed4f..beb4a9a 100644
--- a/src/elements/pcln.cpp
+++ b/src/elements/pcln.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PCLN(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/phot.cpp b/src/elements/phot.cpp
index 3ed6b5d..407ac2e 100644
--- a/src/elements/phot.cpp
+++ b/src/elements/phot.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PHOT(UPDATE_FUNC_ARGS) {
int r, rt, rx, ry;
diff --git a/src/elements/pipe.cpp b/src/elements/pipe.cpp
index 08432f5..40ef411 100644
--- a/src/elements/pipe.cpp
+++ b/src/elements/pipe.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
signed char pos_1_rx[] = {-1,-1,-1, 0, 0, 1, 1, 1};
signed char pos_1_ry[] = {-1, 0, 1,-1, 1,-1, 0, 1};
diff --git a/src/elements/plnt.cpp b/src/elements/plnt.cpp
index a44c8c2..ef7985f 100644
--- a/src/elements/plnt.cpp
+++ b/src/elements/plnt.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PLNT(UPDATE_FUNC_ARGS) {
int r, rx, ry, np;
diff --git a/src/elements/plsm.cpp b/src/elements/plsm.cpp
index c6f7c20..f8b3865 100644
--- a/src/elements/plsm.cpp
+++ b/src/elements/plsm.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
#include "hmap.h"
int graphics_PLSM(GRAPHICS_FUNC_ARGS)
diff --git a/src/elements/plut.cpp b/src/elements/plut.cpp
index 3e2820d..7c51b2d 100644
--- a/src/elements/plut.cpp
+++ b/src/elements/plut.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PLUT(UPDATE_FUNC_ARGS) {
if (1>rand()%100 && ((int)(5.0f*sim->pv[y/CELL][x/CELL]))>(rand()%1000))
diff --git a/src/elements/prti.cpp b/src/elements/prti.cpp
index df212d4..9bbbf26 100644
--- a/src/elements/prti.cpp
+++ b/src/elements/prti.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
/*these are the count values of where the particle gets stored, depending on where it came from
0 1 2
7 . 3
diff --git a/src/elements/prto.cpp b/src/elements/prto.cpp
index ee61abf..32e7251 100644
--- a/src/elements/prto.cpp
+++ b/src/elements/prto.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
/*these are the count values of where the particle gets stored, depending on where it came from
0 1 2
7 . 3
diff --git a/src/elements/pump.cpp b/src/elements/pump.cpp
index 8a7254e..af05c02 100644
--- a/src/elements/pump.cpp
+++ b/src/elements/pump.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PUMP(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/pvod.cpp b/src/elements/pvod.cpp
index e645d0a..1a48ca8 100644
--- a/src/elements/pvod.cpp
+++ b/src/elements/pvod.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PVOD(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/pyro.cpp b/src/elements/pyro.cpp
index 790e295..81f00f7 100644
--- a/src/elements/pyro.cpp
+++ b/src/elements/pyro.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_PYRO(UPDATE_FUNC_ARGS) {
int r, rx, ry, rt, t = parts[i].type;
diff --git a/src/elements/qrtz.cpp b/src/elements/qrtz.cpp
index 7768765..c33cacb 100644
--- a/src/elements/qrtz.cpp
+++ b/src/elements/qrtz.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_QRTZ(UPDATE_FUNC_ARGS) {
int r, tmp, trade, rx, ry, np, t;
diff --git a/src/elements/rime.cpp b/src/elements/rime.cpp
index 617414b..878b928 100644
--- a/src/elements/rime.cpp
+++ b/src/elements/rime.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_RIME(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/shld.cpp b/src/elements/shld.cpp
index cbe8306..ade7edb 100644
--- a/src/elements/shld.cpp
+++ b/src/elements/shld.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SHLD1(UPDATE_FUNC_ARGS) {
int r, nnx, nny, rx, ry;
diff --git a/src/elements/sing.cpp b/src/elements/sing.cpp
index fa6121c..de1e329 100644
--- a/src/elements/sing.cpp
+++ b/src/elements/sing.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SING(UPDATE_FUNC_ARGS) {
int r, rx, ry, cry, crx, rad, nxi, nxj, nb, j, spawncount;
diff --git a/src/elements/sltw.cpp b/src/elements/sltw.cpp
index c965fd4..507602c 100644
--- a/src/elements/sltw.cpp
+++ b/src/elements/sltw.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SLTW(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/smke.cpp b/src/elements/smke.cpp
index d19bd0a..e9311bd 100644
--- a/src/elements/smke.cpp
+++ b/src/elements/smke.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int graphics_SMKE(GRAPHICS_FUNC_ARGS)
{
diff --git a/src/elements/soap.cpp b/src/elements/soap.cpp
index 0d31292..0d1054f 100644
--- a/src/elements/soap.cpp
+++ b/src/elements/soap.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SOAP(UPDATE_FUNC_ARGS)
{
diff --git a/src/elements/spng.cpp b/src/elements/spng.cpp
index 28b3e1b..868b1e6 100644
--- a/src/elements/spng.cpp
+++ b/src/elements/spng.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SPNG(UPDATE_FUNC_ARGS) {
int r, trade, rx, ry, tmp, np;
diff --git a/src/elements/sprk.cpp b/src/elements/sprk.cpp
index 244e831..80f66a2 100644
--- a/src/elements/sprk.cpp
+++ b/src/elements/sprk.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SPRK(UPDATE_FUNC_ARGS) {
int r, rx, ry, rt, conduct_sprk, nearp, pavg, ct = parts[i].ctype;
diff --git a/src/elements/stkm.cpp b/src/elements/stkm.cpp
index 322eba1..c457b62 100644
--- a/src/elements/stkm.cpp
+++ b/src/elements/stkm.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SPAWN(UPDATE_FUNC_ARGS) {
if (!sim->player.spwn)
diff --git a/src/elements/stkm2.cpp b/src/elements/stkm2.cpp
index 967bea2..d18a7ac 100644
--- a/src/elements/stkm2.cpp
+++ b/src/elements/stkm2.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SPAWN2(UPDATE_FUNC_ARGS) {
if (!sim->player2.spwn)
diff --git a/src/elements/stor.cpp b/src/elements/stor.cpp
index 66eb072..414caad 100644
--- a/src/elements/stor.cpp
+++ b/src/elements/stor.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_STOR(UPDATE_FUNC_ARGS) {
int r, rx, ry, np, rx1, ry1;
diff --git a/src/elements/swch.cpp b/src/elements/swch.cpp
index ee2c467..f37192b 100644
--- a/src/elements/swch.cpp
+++ b/src/elements/swch.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_SWCH(UPDATE_FUNC_ARGS) {
int r, rt, rx, ry;
diff --git a/src/elements/thdr.cpp b/src/elements/thdr.cpp
index f7f95b4..1e3d0ab 100644
--- a/src/elements/thdr.cpp
+++ b/src/elements/thdr.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_THDR(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/thrm.cpp b/src/elements/thrm.cpp
index 91939e6..2075e13 100644
--- a/src/elements/thrm.cpp
+++ b/src/elements/thrm.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_THRM(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/uran.cpp b/src/elements/uran.cpp
index a8b2a06..31e93a7 100644
--- a/src/elements/uran.cpp
+++ b/src/elements/uran.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_URAN(UPDATE_FUNC_ARGS) {
if (!sim->legacy_enable && sim->pv[y/CELL][x/CELL]>0.0f)
diff --git a/src/elements/vine.cpp b/src/elements/vine.cpp
index 165d391..c8d51ba 100644
--- a/src/elements/vine.cpp
+++ b/src/elements/vine.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_VINE(UPDATE_FUNC_ARGS) {
int r, np, rx =(rand()%3)-1, ry=(rand()%3)-1;
diff --git a/src/elements/warp.cpp b/src/elements/warp.cpp
index ddc1b81..88315a9 100644
--- a/src/elements/warp.cpp
+++ b/src/elements/warp.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_WARP(UPDATE_FUNC_ARGS) {
int trade, r, rx, ry;
diff --git a/src/elements/watr.cpp b/src/elements/watr.cpp
index 09b66a9..b44fa22 100644
--- a/src/elements/watr.cpp
+++ b/src/elements/watr.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/element.h"
int update_WATR(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/wifi.cpp b/src/elements/wifi.cpp
index ee5e264..cb77dd9 100644
--- a/src/elements/wifi.cpp
+++ b/src/elements/wifi.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_WIFI(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/wire.cpp b/src/elements/wire.cpp
index 49d3720..f7202e4 100644
--- a/src/elements/wire.cpp
+++ b/src/elements/wire.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_WIRE(UPDATE_FUNC_ARGS) {
int s,r,rx,ry,count;
diff --git a/src/elements/wtrv.cpp b/src/elements/wtrv.cpp
index de0eae4..2e3838a 100644
--- a/src/elements/wtrv.cpp
+++ b/src/elements/wtrv.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_WTRV(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/elements/yest.cpp b/src/elements/yest.cpp
index c6c7db6..5b3fc95 100644
--- a/src/elements/yest.cpp
+++ b/src/elements/yest.cpp
@@ -1,4 +1,4 @@
-#include "element.h"
+#include "simulation/Element.h"
int update_YEST(UPDATE_FUNC_ARGS) {
int r, rx, ry;
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index becb540..e029fc9 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -4,6 +4,7 @@
#include "Config.h"
#include "GameController.h"
#include "GameModel.h"
+#include "search/SearchController.h"
#include "interface/Point.h"
using namespace std;
@@ -60,3 +61,9 @@ void GameController::SetPaused(bool pauseState)
{
gameModel->SetPaused(pauseState);
}
+
+void GameController::OpenSearch()
+{
+ SearchController * search = new SearchController();
+ ui::Engine::Ref().ShowWindow(search->GetView());
+}
diff --git a/src/game/GameController.h b/src/game/GameController.h
index c3c8273..d9755a1 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -5,7 +5,7 @@
#include "GameView.h"
#include "GameModel.h"
#include "interface/Point.h"
-#include "Simulation.h"
+#include "simulation/Simulation.h"
using namespace std;
@@ -23,6 +23,7 @@ public:
void DrawPoints(queue<ui::Point*> & pointQueue);
void Tick();
void SetPaused(bool pauseState);
+ void OpenSearch();
};
#endif // GAMECONTROLLER_H
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 96b29a9..3d5a800 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -1,7 +1,7 @@
#include "interface/Engine.h"
#include "GameModel.h"
#include "GameView.h"
-#include "Simulation.h"
+#include "simulation/Simulation.h"
#include "Renderer.h"
GameModel::GameModel():
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index a2eb3ce..6cb74cb 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -2,7 +2,7 @@
#define GAMEMODEL_H
#include <vector>
-#include "Simulation.h"
+#include "simulation/Simulation.h"
#include "Renderer.h"
#include "GameView.h"
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 2576527..2fbed31 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -24,6 +24,21 @@ GameView::GameView():
pauseButton->SetTogglable(true);
pauseButton->SetActionCallback(new PauseAction(this));
AddComponent(pauseButton);
+
+ class SearchAction : public ui::ButtonAction
+ {
+ GameView * v;
+ public:
+ SearchAction(GameView * _v) { v = _v; }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->OpenSearch();
+ }
+ };
+ searchButton = new ui::Button(ui::Point(1, Size.Y-18), ui::Point(16, 16), "\x81"); //Open
+ searchButton->SetTogglable(false);
+ searchButton->SetActionCallback(new SearchAction(this));
+ AddComponent(searchButton);
}
void GameView::NotifyRendererChanged(GameModel * sender)
diff --git a/src/game/GameView.h b/src/game/GameView.h
index 531a4b9..f34aedc 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -21,20 +21,13 @@ private:
Renderer * ren;
//UI Elements
ui::Button * pauseButton;
+ ui::Button * searchButton;
public:
GameView();
void AttachController(GameController * _c){ c = _c; }
void NotifyRendererChanged(GameModel * sender);
void NotifySimulationChanged(GameModel * sender);
void NotifyPausedChanged(GameModel * sender);
- /*virtual void DoMouseMove(int x, int y, int dx, int dy);
- virtual void DoMouseDown(int x, int y, unsigned button);
- virtual void DoMouseUp(int x, int y, unsigned button);
- //virtual void DoMouseWheel(int x, int y, int d);
- //virtual void DoKeyPress(int key, bool shift, bool ctrl, bool alt);
- //virtual void DoKeyRelease(int key, bool shift, bool ctrl, bool alt);
- virtual void DoTick(float dt);
- virtual void DoDraw();*/
virtual void OnMouseMove(int x, int y, int dx, int dy);
virtual void OnMouseDown(int x, int y, unsigned button);
virtual void OnMouseUp(int x, int y, unsigned button);
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp
index a3f76b9..affa75d 100644
--- a/src/interface/Button.cpp
+++ b/src/interface/Button.cpp
@@ -11,6 +11,7 @@
#include "Graphics.h"
#include "Global.h"
#include "Engine.h"
+#include "Misc.h"
namespace ui {
@@ -20,9 +21,12 @@ Button::Button(Window* parent_state, std::string buttonText):
isMouseInside(false),
isButtonDown(false),
isTogglable(false),
- actionCallback(NULL)
+ actionCallback(NULL),
+ textPosition(ui::Point(0, 0)),
+ textVAlign(AlignMiddle),
+ textHAlign(AlignCentre)
{
-
+ TextPosition();
}
Button::Button(Point position, Point size, std::string buttonText):
@@ -31,9 +35,12 @@ Button::Button(Point position, Point size, std::string buttonText):
isMouseInside(false),
isButtonDown(false),
isTogglable(false),
- actionCallback(NULL)
+ actionCallback(NULL),
+ textPosition(ui::Point(0, 0)),
+ textVAlign(AlignMiddle),
+ textHAlign(AlignCentre)
{
-
+ TextPosition();
}
Button::Button(std::string buttonText):
@@ -42,9 +49,48 @@ Button::Button(std::string buttonText):
isMouseInside(false),
isButtonDown(false),
isTogglable(false),
- actionCallback(NULL)
+ actionCallback(NULL),
+ textPosition(ui::Point(0, 0)),
+ textVAlign(AlignMiddle),
+ textHAlign(AlignCentre)
{
+ TextPosition();
+}
+
+void Button::TextPosition()
+{
+ //Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2
+ switch(textVAlign)
+ {
+ case AlignTop:
+ textPosition.Y = 3;
+ break;
+ case AlignMiddle:
+ textPosition.Y = (Size.Y-10)/2;
+ break;
+ case AlignBottom:
+ textPosition.Y = Size.Y-11;
+ break;
+ }
+ switch(textHAlign)
+ {
+ case AlignLeft:
+ textPosition.X = 3;
+ break;
+ case AlignCentre:
+ textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2;
+ break;
+ case AlignRight:
+ textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))-2;
+ break;
+ }
+}
+
+void Button::SetText(std::string buttonText)
+{
+ ButtonText = buttonText;
+ TextPosition();
}
void Button::SetTogglable(bool togglable)
@@ -68,25 +114,21 @@ inline void Button::SetToggleState(bool state)
toggle = state;
}
-
-
void Button::Draw(const Point& screenPos)
{
Graphics * g = ui::Engine::Ref().g;
Point Position = screenPos;
- // = reinterpret_cast<Graphics*>(userdata);
- //TODO: Cache text location, that way we don't have the text alignment code here
if(isButtonDown || (isTogglable && toggle))
{
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255);
- g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2, ButtonText, 0, 0, 0, 255);
+ g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 0, 0, 0, 255);
}
else
{
if(isMouseInside)
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
- g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2, ButtonText, 255, 255, 255, 255);
+ g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
}
/*sf::RenderWindow* rw = reinterpret_cast<sf::RenderWindow*>(userdata); //it better be a RenderWindow or so help your god
diff --git a/src/interface/Button.h b/src/interface/Button.h
index 5f2d71f..aabca91 100644
--- a/src/interface/Button.h
+++ b/src/interface/Button.h
@@ -9,7 +9,7 @@
#define BUTTON_H_
#include <string>
-
+#include "Misc.h"
#include "Component.h"
namespace ui
@@ -51,10 +51,18 @@ public:
inline bool GetToggleState();
inline void SetToggleState(bool state);
void SetActionCallback(ButtonAction * action);
-
+ void TextPosition();
+ void SetText(std::string buttonText);
+ HorizontalAlignment GetHAlignment() { return textHAlign; }
+ VerticalAlignment GetVAlignment() { return textVAlign; }
+ void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
protected:
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
ButtonAction * actionCallback;
+ ui::Point textPosition;
+ HorizontalAlignment textHAlign;
+ VerticalAlignment textVAlign;
+
};
}
#endif /* BUTTON_H_ */
diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp
index 55a2370..130fc8e 100644
--- a/src/interface/Engine.cpp
+++ b/src/interface/Engine.cpp
@@ -47,10 +47,9 @@ void Engine::ShowWindow(Window * window)
{
if(state_)
{
- windows.push(window);
+ windows.push(state_);
}
state_ = window;
- windows.push(window);
}
void Engine::CloseWindow()
diff --git a/src/interface/Sandbox.cpp b/src/interface/Sandbox.cpp
deleted file mode 100644
index 9a858f8..0000000
--- a/src/interface/Sandbox.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Sandbox.cpp
- *
- * Created on: Jan 8, 2012
- * Author: Simon
- */
-
-#include <iostream>
-#include <queue>
-
-#include "Config.h"
-#include "Global.h"
-
-#include "interface/Point.h"
-#include "interface/Sandbox.h"
-#include "interface/Component.h"
-#include "Renderer.h"
-#include "Simulation.h"
-#include "Engine.h"
-
-namespace ui {
-
-Sandbox::Sandbox():
- Component(Point(0, 0), Point(XRES, YRES)),
- pointQueue(std::queue<Point*>()),
- ren(NULL),
- isMouseDown(false),
- activeElement(1)
-{
- sim = new Simulation();
-}
-
-Simulation * Sandbox::GetSimulation()
-{
- return sim;
-}
-
-void Sandbox::OnMouseMoved(int localx, int localy, int dx, int dy)
-{
- if(isMouseDown)
- {
- pointQueue.push(new Point(localx-dx, localy-dy));
- pointQueue.push(new Point(localx, localy));
- }
-}
-
-void Sandbox::OnMouseClick(int localx, int localy, unsigned int button)
-{
- isMouseDown = true;
- pointQueue.push(new Point(localx, localy));
-}
-
-void Sandbox::OnMouseUp(int localx, int localy, unsigned int button)
-{
- if(isMouseDown)
- {
- isMouseDown = false;
- pointQueue.push(new Point(localx, localy));
- }
-}
-
-void Sandbox::Draw(const Point& screenPos)
-{
- Graphics * g = Engine::Ref().g;
- if(!ren)
- ren = new Renderer(g, sim);
- ren->render_parts();
-}
-
-void Sandbox::Tick(float delta)
-{
- if(!pointQueue.empty())
- {
- Point * sPoint = NULL;
- while(!pointQueue.empty())
- {
- Point * fPoint = pointQueue.front();
- pointQueue.pop();
- if(sPoint)
- {
- sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 1, 1, activeElement, 0);
- delete sPoint;
- }
- else
- {
- sim->create_parts(fPoint->X, fPoint->Y, 1, 1, activeElement, 0);
- }
- sPoint = fPoint;
- }
- if(sPoint)
- delete sPoint;
- }
- sim->update_particles();
- sim->sys_pause = 1;
-}
-
-Sandbox::~Sandbox() {
- // TODO Auto-generated destructor stub
-}
-
-} /* namespace ui */
diff --git a/src/interface/Sandbox.h b/src/interface/Sandbox.h
deleted file mode 100644
index fb4a668..0000000
--- a/src/interface/Sandbox.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Sandbox.h
- *
- * Created on: Jan 8, 2012
- * Author: Simon
- */
-
-#ifndef SANDBOX_H_
-#define SANDBOX_H_
-
-#include <queue>
-#include "Point.h"
-#include "Component.h"
-#include "Simulation.h"
-#include "Renderer.h"
-
-namespace ui {
-
-class Sandbox: public ui::Component {
-private:
- int lastCoordX, lastCoordY;
- int activeElement;
- std::queue<Point*> pointQueue;
- bool isMouseDown;
- Renderer * ren;
- Simulation * sim;
-public:
- Sandbox();
- virtual Simulation * GetSimulation();
- virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
- virtual void OnMouseClick(int localx, int localy, unsigned int button);
- virtual void OnMouseUp(int localx, int localy, unsigned int button);
- virtual void Draw(const Point& screenPos);
- virtual void Tick(float delta);
- virtual ~Sandbox();
-};
-
-} /* namespace ui */
-#endif /* SANDBOX_H_ */
diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp
new file mode 100644
index 0000000..18f3281
--- /dev/null
+++ b/src/interface/SaveButton.cpp
@@ -0,0 +1,157 @@
+#include <iostream>
+
+#include "SaveButton.h"
+#include "search/Save.h"
+#include "Graphics.h"
+#include "Global.h"
+#include "Engine.h"
+#include "client/Client.h"
+
+namespace ui {
+
+SaveButton::SaveButton(Window* parent_state, Save save):
+ Component(parent_state),
+ save(save),
+ thumbnail(NULL),
+ isMouseInside(false),
+ isButtonDown(false),
+ actionCallback(NULL)
+{
+
+}
+
+SaveButton::SaveButton(Point position, Point size, Save save):
+ Component(position, size),
+ save(save),
+ thumbnail(NULL),
+ isMouseInside(false),
+ isButtonDown(false),
+ actionCallback(NULL)
+{
+
+}
+
+SaveButton::SaveButton(Save save):
+ Component(),
+ save(save),
+ thumbnail(NULL),
+ isMouseInside(false),
+ isButtonDown(false),
+ actionCallback(NULL)
+{
+
+}
+
+SaveButton::~SaveButton()
+{
+ if(thumbnail)
+ delete thumbnail;
+}
+
+void SaveButton::Tick(float dt)
+{
+ Thumbnail * tempThumb;
+ float scaleFactorY = 1.0f, scaleFactorX = 1.0f;
+ if(!thumbnail)
+ {
+ tempThumb = Client::Ref().GetThumbnail(save.GetID(), 0);
+ if(tempThumb)
+ {
+ thumbnail = tempThumb; //Store a local copy of the thumbnail
+ if(thumbnail->Data)
+ {
+ if(thumbnail->Size.Y > (Size.Y-25))
+ {
+ scaleFactorY = ((float)(Size.Y-25))/((float)thumbnail->Size.Y);
+ }
+ if(thumbnail->Size.X > Size.X)
+ {
+ scaleFactorX = ((float)Size.X)/((float)thumbnail->Size.X);
+ }
+ if(scaleFactorY < 1.0f || scaleFactorX < 1.0f)
+ {
+ float scaleFactor = scaleFactorY < scaleFactorX ? scaleFactorY : scaleFactorX;
+ pixel * thumbData = thumbnail->Data;
+ thumbnail->Data = Graphics::resample_img(thumbData, thumbnail->Size.X, thumbnail->Size.Y, thumbnail->Size.X * scaleFactor, thumbnail->Size.Y * scaleFactor);
+ thumbnail->Size.X *= scaleFactor;
+ thumbnail->Size.Y *= scaleFactor;
+ free(thumbData);
+ }
+ }
+ }
+ }
+}
+
+void SaveButton::Draw(const Point& screenPos)
+{
+ Graphics * g = ui::Engine::Ref().g;
+ float scaleFactor;
+
+ if(thumbnail)
+ {
+ g->draw_image(thumbnail->Data, screenPos.X+(Size.X-thumbnail->Size.X)/2, screenPos.Y+((Size.Y-25)-thumbnail->Size.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
+ g->drawrect(screenPos.X+(Size.X-thumbnail->Size.X)/2, screenPos.Y+((Size.Y-25)-thumbnail->Size.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 180, 180, 180, 255);
+ }
+ else
+ {
+ scaleFactor = (Size.Y-25)/((float)YRES);
+ g->drawrect(screenPos.X+(Size.X-((float)XRES)*scaleFactor)/2, screenPos.Y+((Size.Y-21)-((float)YRES)*scaleFactor)/2, ((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor, 180, 180, 180, 255);
+ }
+
+ if(isMouseInside)
+ {
+ g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
+ g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.name.c_str()))/2, screenPos.Y+Size.Y - 21, save.name, 255, 255, 255, 255);
+ g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.userName.c_str()))/2, screenPos.Y+Size.Y - 10, save.userName, 200, 230, 255, 255);
+ }
+ else
+ {
+ g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.name.c_str()))/2, screenPos.Y+Size.Y - 21, save.name, 180, 180, 180, 255);
+ g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.userName.c_str()))/2, screenPos.Y+Size.Y - 10, save.userName, 100, 130, 160, 255);
+ }
+}
+
+void SaveButton::OnMouseUnclick(int x, int y, unsigned int button)
+{
+ if(button != 1)
+ {
+ return; //left click only!
+ }
+
+ if(isButtonDown)
+ {
+ DoAction();
+ }
+
+ isButtonDown = false;
+}
+
+void SaveButton::OnMouseClick(int x, int y, unsigned int button)
+{
+ if(button != 1) return; //left click only!
+ isButtonDown = true;
+}
+
+void SaveButton::OnMouseEnter(int x, int y)
+{
+ isMouseInside = true;
+}
+
+void SaveButton::OnMouseLeave(int x, int y)
+{
+ isMouseInside = false;
+}
+
+void SaveButton::DoAction()
+{
+ std::cout << "Do action!" << std::endl;
+ if(actionCallback)
+ actionCallback->ActionCallback(this);
+}
+
+void SaveButton::SetActionCallback(SaveButtonAction * action)
+{
+ actionCallback = action;
+}
+
+} /* namespace ui */
diff --git a/src/interface/SaveButton.h b/src/interface/SaveButton.h
new file mode 100644
index 0000000..8834d8a
--- /dev/null
+++ b/src/interface/SaveButton.h
@@ -0,0 +1,50 @@
+#ifndef SAVEBUTTON_H_
+#define SAVEBUTTON_H_
+
+#include <string>
+
+#include "Component.h"
+#include "search/Save.h"
+#include "Graphics.h"
+#include "search/Thumbnail.h"
+
+namespace ui
+{
+class SaveButton;
+class SaveButtonAction
+{
+public:
+ virtual void ActionCallback(ui::SaveButton * sender) {}
+};
+
+class SaveButton : public Component
+{
+ Save save;
+ Thumbnail * thumbnail;
+public:
+ SaveButton(Window* parent_state, Save save);
+
+ SaveButton(Point position, Point size, Save save);
+
+ SaveButton(Save save);
+ virtual ~SaveButton();
+
+ virtual void OnMouseClick(int x, int y, unsigned int button);
+ virtual void OnMouseUnclick(int x, int y, unsigned int button);
+
+ virtual void OnMouseEnter(int x, int y);
+ virtual void OnMouseLeave(int x, int y);
+
+ virtual void Draw(const Point& screenPos);
+ virtual void Tick(float dt);
+
+ inline bool GetState() { return state; }
+ virtual void DoAction();
+ void SetActionCallback(SaveButtonAction * action);
+protected:
+ bool isButtonDown, state, isMouseInside;
+ SaveButtonAction * actionCallback;
+};
+}
+#endif /* BUTTON_H_ */
+
diff --git a/src/search/Save.h b/src/search/Save.h
index a3ef485..91a1ec4 100644
--- a/src/search/Save.h
+++ b/src/search/Save.h
@@ -10,8 +10,6 @@ class Save
private:
int id;
int votesUp, votesDown;
- string userName;
- string name;
public:
Save(int _id, int _votesUp, int _votesDown, string _userName, string _name):
id(_id),
@@ -22,6 +20,9 @@ public:
{
}
+ string userName;
+ string name;
+
void SetName(string name){ this->name = name; }
string GetName(){ return name; }
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index cf13f2e..90750e0 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -8,6 +8,9 @@ SearchController::SearchController()
searchModel = new SearchModel();
searchView = new SearchView();
searchModel->AddObserver(searchView);
+ searchView->AttachController(this);
+
+ searchModel->UpdateSaveList();
//Set up interface
//windowPanel.AddChild();
diff --git a/src/search/SearchController.h b/src/search/SearchController.h
index 8755a07..10dd9bd 100644
--- a/src/search/SearchController.h
+++ b/src/search/SearchController.h
@@ -4,15 +4,16 @@
#include "interface/Panel.h"
#include "SearchModel.h"
#include "SearchView.h"
-
+class SearchView;
+class SearchModel;
class SearchController
{
private:
SearchModel * searchModel;
SearchView * searchView;
- ui::Panel * windowPanel;
public:
SearchController();
+ SearchView * GetView() { return searchView; }
};
#endif // SEARCHCONTROLLER_H
diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp
index 63188bd..494d490 100644
--- a/src/search/SearchModel.cpp
+++ b/src/search/SearchModel.cpp
@@ -9,10 +9,24 @@ void SearchModel::UpdateSaveList()
{
saveList.clear();
notifySaveListChanged();
- saveList.push_back(Save(1, 45, 5, "Simon", "Post logic gates"));
+ for(int i = 0; i < 16; i++)
+ {
+ saveList.push_back(Save(2198, 2333, 315, "dima-gord", "Destroyable city 5 (wth metro)"));
+ }
notifySaveListChanged();
}
+vector<Save> SearchModel::GetSaveList()
+{
+ return saveList;
+}
+
+void SearchModel::AddObserver(SearchView * observer)
+{
+ observers.push_back(observer);
+ observer->NotifySaveListChanged(this);
+}
+
void SearchModel::notifySaveListChanged()
{
for(int i = 0; i < observers.size(); i++)
diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h
index 0951577..85d4177 100644
--- a/src/search/SearchModel.h
+++ b/src/search/SearchModel.h
@@ -7,6 +7,7 @@
using namespace std;
+class SearchView;
class SearchModel
{
private:
@@ -15,7 +16,7 @@ private:
void notifySaveListChanged();
public:
SearchModel();
- void AddObserver(SearchView * observer){ observers.push_back(observer); }
+ void AddObserver(SearchView * observer);
void UpdateSaveList();
vector<Save> GetSaveList();
};
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 4b551f3..29d6eef 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -1,10 +1,60 @@
#include "SearchView.h"
+#include "interface/SaveButton.h"
+#include "Misc.h"
-SearchView::SearchView()
+SearchView::SearchView():
+ ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
+ saveButtons(vector<ui::SaveButton*>())
{
+ nextButton = new ui::Button(ui::Point(XRES+BARSIZE-52, YRES+MENUSIZE-18), ui::Point(50, 16), "Next \x95");
+ previousButton = new ui::Button(ui::Point(1, YRES+MENUSIZE-18), ui::Point(50, 16), "\x96 Prev");
+
+ nextButton->SetAlignment(AlignRight, AlignBottom);
+ previousButton->SetAlignment(AlignLeft, AlignBottom);
+ AddComponent(nextButton);
+ AddComponent(previousButton);
}
-void SearchView::NotifySaveListChanged(SearchModel * sender)
+SearchView::~SearchView()
{
+}
+void SearchView::NotifySaveListChanged(SearchModel * sender)
+{
+ int i = 0;
+ int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 4, savesY = 3, buttonPadding = 2;
+ int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
+ buttonXOffset = 0;
+ buttonYOffset = 50;
+ buttonAreaWidth = Size.X;
+ buttonAreaHeight = Size.Y - buttonYOffset - 18;
+ buttonWidth = (buttonAreaWidth/savesX) - buttonPadding*2;
+ buttonHeight = (buttonAreaHeight/savesY) - buttonPadding*2;
+ for(i = 0; i < saveButtons.size(); i++)
+ {
+ RemoveComponent(saveButtons[i]);
+ delete saveButtons[i];
+ }
+ vector<Save> saves = sender->GetSaveList();
+ for(i = 0; i < saves.size(); i++)
+ {
+ if(saveX == savesX)
+ {
+ if(saveY == savesY-1)
+ break;
+ saveX = 0;
+ saveY++;
+ }
+ ui::SaveButton * saveButton;
+ saveButton = new ui::SaveButton(
+ ui::Point(
+ buttonXOffset + buttonPadding + saveX*(buttonWidth+buttonPadding*2),
+ buttonYOffset + buttonPadding + saveY*(buttonHeight+buttonPadding*2)
+ ),
+ ui::Point(buttonWidth, buttonHeight),
+ saves[i]);
+ saveButtons.push_back(saveButton);
+ AddComponent(saveButton);
+ saveX++;
+ }
}
diff --git a/src/search/SearchView.h b/src/search/SearchView.h
index e540f21..c68d42c 100644
--- a/src/search/SearchView.h
+++ b/src/search/SearchView.h
@@ -1,13 +1,28 @@
#ifndef SEARCHVIEW_H
#define SEARCHVIEW_H
+#include <vector>
+#include "SearchController.h"
+#include "interface/SaveButton.h"
+#include "interface/Button.h"
+
+using namespace std;
+
class SearchModel;
+class SearchController;
-class SearchView
+class SearchView: public ui::Window
{
+private:
+ SearchController * c;
+ vector<ui::SaveButton*> saveButtons;
+ ui::Button * nextButton;
+ ui::Button * previousButton;
public:
void NotifySaveListChanged(SearchModel * sender);
SearchView();
+ virtual ~SearchView();
+ void AttachController(SearchController * _c) { c = _c; }
};
#endif // SEARCHVIEW_H
diff --git a/src/search/Thumbnail.h b/src/search/Thumbnail.h
new file mode 100644
index 0000000..3b865ca
--- /dev/null
+++ b/src/search/Thumbnail.h
@@ -0,0 +1,49 @@
+#ifndef THUMBNAIL_H
+#define THUMBNAIL_H
+
+#include "Graphics.h"
+#include "interface/Point.h"
+
+class Thumbnail
+{
+public:
+ Thumbnail(const Thumbnail & thumb):
+ ID(thumb.ID),
+ Datestamp(thumb.Datestamp),
+ Data(thumb.Data),
+ Size(thumb.Size)
+ {
+ //Ensure the actual thumbnail data is copied
+ if(thumb.Data)
+ {
+ Data = (pixel *)malloc((thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
+ memcpy(Data, thumb.Data, (thumb.Size.X*thumb.Size.Y) * PIXELSIZE);
+ }
+ else
+ {
+ Data = NULL;
+ }
+ }
+
+ Thumbnail(int _id, int _datestamp, pixel * _data, ui::Point _size):
+ ID(_id),
+ Datestamp(_datestamp),
+ Data(_data),
+ Size(_size)
+ {
+ }
+
+ ~Thumbnail()
+ {
+ if(Data)
+ {
+ free(Data);
+ }
+ }
+
+ int ID, Datestamp;
+ ui::Point Size;
+ pixel * Data;
+};
+
+#endif // THUMBNAIL_H
diff --git a/src/Air.cpp b/src/simulation/Air.cpp
index 2d8d1b5..2d8d1b5 100644
--- a/src/Air.cpp
+++ b/src/simulation/Air.cpp
diff --git a/src/Air.h b/src/simulation/Air.h
index 8e4dc25..8e4dc25 100644
--- a/src/Air.h
+++ b/src/simulation/Air.h
diff --git a/src/Element.h b/src/simulation/Element.h
index 449bf51..449bf51 100644
--- a/src/Element.h
+++ b/src/simulation/Element.h
diff --git a/src/ElementFunctions.h b/src/simulation/ElementFunctions.h
index ef80b6f..ef80b6f 100644
--- a/src/ElementFunctions.h
+++ b/src/simulation/ElementFunctions.h
diff --git a/src/ElementGraphics.h b/src/simulation/ElementGraphics.h
index a880e71..a880e71 100644
--- a/src/ElementGraphics.h
+++ b/src/simulation/ElementGraphics.h
diff --git a/src/Elements.h b/src/simulation/Elements.h
index 204460c..204460c 100644
--- a/src/Elements.h
+++ b/src/simulation/Elements.h
diff --git a/src/Gravity.cpp b/src/simulation/Gravity.cpp
index cc20b2f..cc20b2f 100644
--- a/src/Gravity.cpp
+++ b/src/simulation/Gravity.cpp
diff --git a/src/Gravity.h b/src/simulation/Gravity.h
index 9f36240..9f36240 100644
--- a/src/Gravity.h
+++ b/src/simulation/Gravity.h
diff --git a/src/Simulation.cpp b/src/simulation/Simulation.cpp
index a1a785a..a1a785a 100644
--- a/src/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
diff --git a/src/Simulation.h b/src/simulation/Simulation.h
index b3c51af..b3c51af 100644
--- a/src/Simulation.h
+++ b/src/simulation/Simulation.h