--- a/hedgewars/ArgParsers.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/ArgParsers.pas Sat Sep 27 12:49:08 2014 +0400
@@ -204,8 +204,8 @@
otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
allarray: array [0..17] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
- reallyAll: array[0..34] of shortstring = (
- '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
+ reallyAll: array[0..32] of shortstring = (
+ '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
'--height', '--frame-interval', '--volume','--nomusic', '--nosound',
'--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
{deprecated} '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
@@ -221,44 +221,42 @@
while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
case cmdIndex of
- {--prefix} 0 : PathPrefix := getstringParameter (arg, paramIndex, parseParameter);
- {--user-prefix} 1 : UserPathPrefix := getstringParameter (arg, paramIndex, parseParameter);
- {--locale} 2 : cLocaleFName := getstringParameter (arg, paramIndex, parseParameter);
- {--fullscreen-width} 3 : cFullscreenWidth := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
- {--fullscreen-height} 4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
- {--width} 5 : cWindowedWidth := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
- {--height} 6 : cWindowedHeight := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
- {--frame-interval} 7 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
- {--volume} 8 : SetVolume ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
- {--nomusic} 9 : SetMusic ( false );
- {--nosound} 10 : SetSound ( false );
- {--fullscreen} 11 : cFullScreen := true;
- {--showfps} 12 : cShowFPS := true;
- {--altdmg} 13 : cAltDamage := true;
- {--low-quality} 14 : cReducedQuality := $FFFFFFFF xor rqLowRes;
- {--raw-quality} 15 : cReducedQuality := getLongIntParameter(arg, paramIndex, parseParameter);
- {--stereo} 16 : setStereoMode ( getLongIntParameter(arg, paramIndex, parseParameter) );
- {--nick} 17 : UserNick := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
+ {--locale} 0 : cLocaleFName := getstringParameter (arg, paramIndex, parseParameter);
+ {--fullscreen-width} 1 : cFullscreenWidth := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
+ {--fullscreen-height} 2 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
+ {--width} 3 : cWindowedWidth := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
+ {--height} 4 : cWindowedHeight := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
+ {--frame-interval} 5 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
+ {--volume} 6 : SetVolume ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
+ {--nomusic} 7 : SetMusic ( false );
+ {--nosound} 8 : SetSound ( false );
+ {--fullscreen} 9 : cFullScreen := true;
+ {--showfps} 10 : cShowFPS := true;
+ {--altdmg} 11 : cAltDamage := true;
+ {--low-quality} 12 : cReducedQuality := $FFFFFFFF xor rqLowRes;
+ {--raw-quality} 13 : cReducedQuality := getLongIntParameter(arg, paramIndex, parseParameter);
+ {--stereo} 14 : setStereoMode ( getLongIntParameter(arg, paramIndex, parseParameter) );
+ {--nick} 15 : UserNick := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
{deprecated options}
- {--depth} 18 : setDepth(paramIndex);
- {--set-video} 19 : parseClassicParameter(videoarray,5,paramIndex);
- {--set-audio} 20 : parseClassicParameter(audioarray,3,paramIndex);
- {--set-other} 21 : parseClassicParameter(otherarray,3,paramIndex);
- {--set-multimedia} 22 : parseClassicParameter(mediaarray,10,paramIndex);
- {--set-everything} 23 : parseClassicParameter(allarray,14,paramIndex);
+ {--depth} 16 : setDepth(paramIndex);
+ {--set-video} 17 : parseClassicParameter(videoarray,5,paramIndex);
+ {--set-audio} 18 : parseClassicParameter(audioarray,3,paramIndex);
+ {--set-other} 19 : parseClassicParameter(otherarray,3,paramIndex);
+ {--set-multimedia} 20 : parseClassicParameter(mediaarray,10,paramIndex);
+ {--set-everything} 21 : parseClassicParameter(allarray,14,paramIndex);
{"internal" options}
- {--internal} 24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
- {--recorder} 25 : startVideoRecording(paramIndex);
- {--landpreview} 26 : GameType := gmtLandPreview;
+ {--internal} 22 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
+ {--recorder} 23 : startVideoRecording(paramIndex);
+ {--landpreview} 24 : GameType := gmtLandPreview;
{anything else}
- {--stats-only} 27 : statsOnlyGame();
- {--gci} 28 : GciEasterEgg();
- {--help} 29 : DisplayUsage();
- {--no-teamtag} 30 : cTagsMask := cTagsMask and (not htTeamName);
- {--no-hogtag} 31 : cTagsMask := cTagsMask and (not htName);
- {--no-healthtag} 32 : cTagsMask := cTagsMask and (not htHealth);
- {--translucent-tags} 33 : cTagsMask := cTagsMask or htTransparent;
- {--lua-test} 34: begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
+ {--stats-only} 25 : statsOnlyGame();
+ {--gci} 26 : GciEasterEgg();
+ {--help} 27 : DisplayUsage();
+ {--no-teamtag} 28 : cTagsMask := cTagsMask and (not htTeamName);
+ {--no-hogtag} 29 : cTagsMask := cTagsMask and (not htName);
+ {--no-healthtag} 30 : cTagsMask := cTagsMask and (not htHealth);
+ {--translucent-tags} 31 : cTagsMask := cTagsMask or htTransparent;
+ {--lua-test} 32: begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
else
begin
//Assume the first "non parameter" is the replay file, anything else is invalid
@@ -354,8 +352,6 @@
begin
isInternal:= (ParamStr(1) = '--internal');
- UserPathPrefix := _S'.';
- PathPrefix := cDefaultPathPrefix;
recordFileName := '';
parseCommandLine();
--- a/hedgewars/hwLibrary.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/hwLibrary.pas Sat Sep 27 12:49:08 2014 +0400
@@ -41,6 +41,7 @@
, uFLTypes
, uFLGameConfig
, uFLIPC
+ , uPhysFSLayer
;
{$INCLUDE "config.inc"}
@@ -99,9 +100,16 @@
ReleaseSound(false);
end;
-procedure flibInit; cdecl; export;
+procedure flibInit(localPrefix, userPrefix: PChar); cdecl; export;
begin
- initIPC
+ initIPC;
+ uPhysFSLayer.initModule(localPrefix, userPrefix);
+end;
+
+procedure flibFree; cdecl; export;
+begin
+ uPhysFSLayer.freemodule;
+ freeIPC;
end;
{$IFDEF ANDROID}
@@ -139,6 +147,7 @@
registerIPCCallback,
ipcToEngine,
flibInit,
+ flibFree,
LoadLocaleWrapper,
HW_versionInfo,
HW_versionString,
--- a/hedgewars/hwengine.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/hwengine.pas Sat Sep 27 12:49:08 2014 +0400
@@ -322,8 +322,8 @@
initEverything(true);
WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString +
' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion));
- AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"');
- AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"');
+ //AddFileLog('Prefix: "' + shortstring(PathPrefix) +'"');
+ //AddFileLog('UserPrefix: "' + shortstring(UserPathPrefix) +'"');
for i:= 0 to ParamCount do
AddFileLog(inttostr(i) + ': ' + ParamStr(i));
@@ -385,7 +385,6 @@
begin
if recordFileName = '' then
begin
- InitIPC;
SendIPCAndWaitReply(_S'C'); // ask for game config
end
else
@@ -444,7 +443,6 @@
uLand.initModule; // computes land
uLandPainted.initModule; // computes drawn land
uIO.initModule; // sets up sockets
- uPhysFSLayer.initModule;
uScript.initModule;
if complete then
@@ -513,7 +511,6 @@
uCommands.freeModule;
uVariables.freeModule;
uUtils.freeModule; // closes debug file
- uPhysFSLayer.freeModule;
uScript.freeModule;
end;
@@ -523,7 +520,6 @@
begin
initEverything(false);
- InitIPC;
IPCWaitPongEvent;
TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
--- a/hedgewars/uIO.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/uIO.pas Sat Sep 27 12:49:08 2014 +0400
@@ -25,7 +25,6 @@
procedure initModule;
procedure freeModule;
-procedure InitIPC;
procedure SendIPC(s: shortstring);
procedure SendIPCXY(cmd: char; X, Y: LongInt);
procedure SendIPCRaw(p: pointer; len: Longword);
@@ -99,11 +98,6 @@
dispose(tmp)
end;
-procedure InitIPC;
-begin
- // do nothing, flib initialized everything for us
-end;
-
procedure ParseChatCommand(command: shortstring; message: shortstring;
messageStartIndex: Byte);
var
--- a/hedgewars/uMisc.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/uMisc.pas Sat Sep 27 12:49:08 2014 +0400
@@ -256,7 +256,8 @@
// allocate and fill structure that will be passed to new thread
New(image); // will be disposed in SaveScreenshot()
-image^.filename:= shortstring(UserPathPrefix) + filename + ext;
+//image^.filename:= shortstring(UserPathPrefix) + filename + ext;
+image^.filename:= filename + ext;
image^.width:= cScreenWidth div k;
image^.height:= cScreenHeight div k;
image^.size:= size;
--- a/hedgewars/uPhysFSLayer.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/uPhysFSLayer.pas Sat Sep 27 12:49:08 2014 +0400
@@ -13,7 +13,7 @@
{$linklib physlayer}
{$ENDIF}
-procedure initModule;
+procedure initModule(localPrefix, userPrefix: PChar);
procedure freeModule;
type PFSFile = pointer;
@@ -138,9 +138,9 @@
procedure pfsMount(path: ansistring; mountpoint: PChar);
begin
if PHYSFS_mount(PChar(path), mountpoint, false) then
- AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : ok')
+ //AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : ok')
else
- AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")');
+ //AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")');
end;
procedure pfsMountAtRoot(path: ansistring);
@@ -148,20 +148,16 @@
pfsMount(path, PChar(_S'/'));
end;
-procedure initModule;
+procedure initModule(localPrefix, userPrefix: PChar);
var i: LongInt;
cPhysfsId: shortstring;
fp: PChar;
begin
-{$IFDEF HWLIBRARY}
//TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}{$IFNDEF IPHONEOS}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF}{$ENDIF} ' hedgewars';
-{$ELSE}
- cPhysfsId:= ParamStr(0);
-{$ENDIF}
i:= PHYSFS_init(Str2PChar(cPhysfsId));
- AddFileLog('[PhysFS] init: ' + inttostr(i));
+ //AddFileLog('[PhysFS] init: ' + inttostr(i));
// mount system fonts paths first
for i:= low(cFontsPaths) to high(cFontsPaths) do
@@ -171,13 +167,13 @@
pfsMount(ansistring(fp), PChar('/Fonts'));
end;
- pfsMountAtRoot(PathPrefix);
- pfsMountAtRoot(UserPathPrefix + ansistring('/Data'));
+ pfsMountAtRoot(localPrefix);
+ pfsMountAtRoot(userPrefix + ansistring('/Data'));
hedgewarsMountPackages;
// need access to teams and frontend configs (for bindings)
- pfsMountAtRoot(UserPathPrefix);
+ pfsMountAtRoot(userPrefix);
{$IFNDEF PAS2C}
if cTestLua then
--- a/hedgewars/uUtils.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/uUtils.pas Sat Sep 27 12:49:08 2014 +0400
@@ -524,7 +524,7 @@
{$IFNDEF PAS2C}
f:= stderr; // if everything fails, write to stderr
{$ENDIF}
- if (length(UserPathPrefix) > 0) then
+(* if (length(UserPathPrefix) > 0) then
begin
{$IFNDEF PAS2C}
// create directory if it doesn't exist
@@ -540,7 +540,7 @@
break;
inc(i)
end;
- end;
+ end;*)
Rewrite(f);
{$I+}
{$ENDIF}
--- a/hedgewars/uVariables.pas Fri Sep 26 00:56:36 2014 +0400
+++ b/hedgewars/uVariables.pas Sat Sep 27 12:49:08 2014 +0400
@@ -40,8 +40,6 @@
cLocaleFName : shortstring;
cLocale : shortstring;
cTimerInterval : LongInt;
- PathPrefix : ansistring;
- UserPathPrefix : ansistring;
cShowFPS : boolean;
cFlattenFlakes : boolean;
cFlattenClouds : boolean;
@@ -2423,12 +2421,10 @@
cLocaleFName := 'en.txt';
cFullScreen := false;
- UserPathPrefix := '';
recordFileName := '';
UserNick := '';
cStereoMode := smNone;
GrayScale := false;
- PathPrefix := './';
GameType := gmtLocal;
cOnlyStats := False;
cScriptName := '';
--- a/qmlFrontend/flib.h Fri Sep 26 00:56:36 2014 +0400
+++ b/qmlFrontend/flib.h Sat Sep 27 12:49:08 2014 +0400
@@ -21,7 +21,8 @@
typedef void RunEngine_t(int argc, const char ** argv);
typedef void registerIPCCallback_t(void * context, void (*)(void * context, const char * msg, uint32_t len));
typedef void ipcToEngine_t(const char * msg, uint8_t len);
-typedef void flibInit_t();
+typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
+typedef void flibFree_t();
#ifdef __cplusplus
}
--- a/qmlFrontend/hwengine.cpp Fri Sep 26 00:56:36 2014 +0400
+++ b/qmlFrontend/hwengine.cpp Sat Sep 27 12:49:08 2014 +0400
@@ -2,6 +2,7 @@
#include <QtQml>
#include <QDebug>
#include <QPainter>
+#include <QUuid>
#include "hwengine.h"
#include "previewimageprovider.h"
@@ -11,6 +12,7 @@
registerIPCCallback_t *registerIPCCallback;
ipcToEngine_t *ipcToEngine;
flibInit_t *flibInit;
+ flibFree_t *flibFree;
}
HWEngine::HWEngine(QQmlEngine *engine, QObject *parent) :
@@ -26,14 +28,15 @@
registerIPCCallback = (registerIPCCallback_t*) hwlib.resolve("registerIPCCallback");
ipcToEngine = (ipcToEngine_t*) hwlib.resolve("ipcToEngine");
flibInit = (flibInit_t*) hwlib.resolve("flibInit");
+ flibFree = (flibFree_t*) hwlib.resolve("flibFree");
- flibInit();
+ flibInit(".", "~/.hedgewars");
registerIPCCallback(this, &engineMessageCallback);
}
HWEngine::~HWEngine()
{
-
+ flibFree();
}
void HWEngine::run()
@@ -41,18 +44,16 @@
m_argsList.clear();
m_argsList << "";
m_argsList << "--internal";
- //m_argsList << "--user-prefix";
- //m_argsList << cfgdir->absolutePath();
- //m_argsList << "--prefix";
- //m_argsList << datadir->absolutePath();
m_argsList << "--landpreview";
m_args.resize(m_argsList.size());
for(int i = m_argsList.size() - 1; i >=0; --i)
m_args[i] = m_argsList[i].constData();
+ m_seed = QUuid::createUuid().toString();
+
RunEngine(m_args.size(), m_args.data());
- sendIPC("eseed helloworld");
+ sendIPC("eseed " + m_seed.toLatin1());
sendIPC("e$mapgen 0");
sendIPC("!");
}
@@ -91,26 +92,12 @@
void HWEngine::engineMessageHandler(const QByteArray &msg)
{
- if(msg.size() == 128 * 256)
- {
- QVector<QRgb> colorTable;
- colorTable.resize(256);
- for(int i = 0; i < 256; ++i)
- colorTable[i] = qRgba(255, 255, 0, i);
-
- const quint8 *buf = (const quint8*) msg.constData();
- QImage im(buf, 256, 128, QImage::Format_Indexed8);
- im.setColorTable(colorTable);
+ PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
+ preview->setPixmap(msg);
+ emit previewImageChanged();
+}
- QPixmap px = QPixmap::fromImage(im, Qt::ColorOnly);
- //QPixmap pxres(px.size());
- //QPainter p(&pxres);
-
- //p.fillRect(pxres.rect(), linearGrad);
- //p.drawPixmap(0, 0, px);
-
- PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
- preview->setPixmap(px);
- emit previewImageChanged();
- }
+QString HWEngine::currentSeed()
+{
+ return m_seed;
}
--- a/qmlFrontend/hwengine.h Fri Sep 26 00:56:36 2014 +0400
+++ b/qmlFrontend/hwengine.h Sat Sep 27 12:49:08 2014 +0400
@@ -19,6 +19,7 @@
static void exposeToQML();
Q_INVOKABLE void run();
+ Q_INVOKABLE QString currentSeed();
signals:
void previewImageChanged();
@@ -29,6 +30,7 @@
QList<QByteArray> m_argsList;
QVector<const char *> m_args;
QQmlEngine * m_engine;
+ QString m_seed;
static void engineMessageCallback(void *context, const char * msg, quint32 len);
void sendIPC(const QByteArray &b);
--- a/qmlFrontend/previewimageprovider.cpp Fri Sep 26 00:56:36 2014 +0400
+++ b/qmlFrontend/previewimageprovider.cpp Sat Sep 27 12:49:08 2014 +0400
@@ -16,7 +16,24 @@
return m_px;
}
-void PreviewImageProvider::setPixmap(const QPixmap & px)
+void PreviewImageProvider::setPixmap(const QByteArray &px)
{
- m_px = px;
+ if(px.size() == 128 * 256)
+ {
+ QVector<QRgb> colorTable;
+ colorTable.resize(256);
+ for(int i = 0; i < 256; ++i)
+ colorTable[i] = qRgba(255, 255, 0, i);
+
+ const quint8 *buf = (const quint8*) px.constData();
+ QImage im(buf, 256, 128, QImage::Format_Indexed8);
+ im.setColorTable(colorTable);
+
+ m_px = QPixmap::fromImage(im, Qt::ColorOnly);
+ //QPixmap pxres(px.size());
+ //QPainter p(&pxres);
+
+ //p.fillRect(pxres.rect(), linearGrad);
+ //p.drawPixmap(0, 0, px);
+ }
}
--- a/qmlFrontend/previewimageprovider.h Fri Sep 26 00:56:36 2014 +0400
+++ b/qmlFrontend/previewimageprovider.h Sat Sep 27 12:49:08 2014 +0400
@@ -12,7 +12,7 @@
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
- void setPixmap(const QPixmap & px);
+ void setPixmap(const QByteArray & px);
private:
QPixmap m_px;
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml Fri Sep 26 00:56:36 2014 +0400
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml Sat Sep 27 12:49:08 2014 +0400
@@ -15,7 +15,7 @@
Connections {
target: HWEngine
- onPreviewImageChanged: previewImage.source = "image://preview/1"
+ onPreviewImageChanged: previewImage.source = "image://preview/" + HWEngine.currentSeed()
}
}