diff --git a/Makefile b/Makefile index 490862613..5c9e6d988 100644 --- a/Makefile +++ b/Makefile @@ -65,13 +65,13 @@ all: openmw esmtool niftool bsatool bored cpp: cpp_ogre.o cpp_avcodec.o cpp_bullet.o cpp_ogre.o: $(ogre_cpp_files) - $(OGCC) -c $< + $(OGCC) -o $@ -c $< cpp_avcodec.o: $(avcodec_cpp_files) - $(AVGCC) -c $< + $(AVGCC) -o $@ -c $< cpp_bullet.o: $(bullet_cpp_files) - $(BGCC) -c $< + $(BGCC) -o $@ -c $< objs/%.o: %.d dirname $@ | xargs mkdir -p diff --git a/bullet/cpp_bullet.cpp b/bullet/cpp_bullet.cpp index 0e0959a86..e347049b4 100644 --- a/bullet/cpp_bullet.cpp +++ b/bullet/cpp_bullet.cpp @@ -150,7 +150,7 @@ extern "C" int32_t bullet_init() // ------- SET UP THE PLAYER ------- // Create the player collision shape. - float width = 50; + float width = 30; /* float height = 50; diff --git a/media_mygui/bigbars.png b/media_mygui/bigbars.png new file mode 100644 index 000000000..ee91da19e Binary files /dev/null and b/media_mygui/bigbars.png differ diff --git a/media_mygui/core.skin b/media_mygui/core.skin index ccd44a339..ce497b9b2 100644 --- a/media_mygui/core.skin +++ b/media_mygui/core.skin @@ -10,7 +10,7 @@ - + diff --git a/media_mygui/core.xml b/media_mygui/core.xml index 1972c2372..5a772d28e 100644 --- a/media_mygui/core.xml +++ b/media_mygui/core.xml @@ -14,8 +14,11 @@ + + + diff --git a/media_mygui/openmw.font.xml b/media_mygui/openmw.font.xml index 30c861254..164d1edbf 100644 --- a/media_mygui/openmw.font.xml +++ b/media_mygui/openmw.font.xml @@ -24,6 +24,14 @@ + + + + + + + + diff --git a/media_mygui/openmw_box.skin.xml b/media_mygui/openmw_box.skin.xml new file mode 100644 index 000000000..683c9c146 --- /dev/null +++ b/media_mygui/openmw_box.skin.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media_mygui/openmw_hud_box.skin.xml b/media_mygui/openmw_hud_box.skin.xml index 7b2890a56..1f91c66b5 100644 --- a/media_mygui/openmw_hud_box.skin.xml +++ b/media_mygui/openmw_hud_box.skin.xml @@ -1,7 +1,7 @@ - + @@ -15,7 +15,6 @@ - diff --git a/media_mygui/openmw_hud_energybar.skin.xml b/media_mygui/openmw_hud_energybar.skin.xml index 28c7a2928..6b0bef484 100644 --- a/media_mygui/openmw_hud_energybar.skin.xml +++ b/media_mygui/openmw_hud_energybar.skin.xml @@ -27,24 +27,19 @@ - - - + + + - - - + + + - - - - - - - - + + + @@ -74,12 +69,4 @@ - - - - - - - - diff --git a/media_mygui/openmw_mainmenu_layout.xml b/media_mygui/openmw_mainmenu_layout.xml new file mode 100644 index 000000000..bf17be7f7 --- /dev/null +++ b/media_mygui/openmw_mainmenu_layout.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/media_mygui/openmw_mainmenu_skin.xml b/media_mygui/openmw_mainmenu_skin.xml new file mode 100644 index 000000000..4679430cc --- /dev/null +++ b/media_mygui/openmw_mainmenu_skin.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media_mygui/openmw_map_window_layout.xml b/media_mygui/openmw_map_window_layout.xml new file mode 100644 index 000000000..f4ff50f72 --- /dev/null +++ b/media_mygui/openmw_map_window_layout.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/media_mygui/openmw_progress.skin.xml b/media_mygui/openmw_progress.skin.xml new file mode 100644 index 000000000..51a027ac4 --- /dev/null +++ b/media_mygui/openmw_progress.skin.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media_mygui/openmw_stats_window_layout.xml b/media_mygui/openmw_stats_window_layout.xml new file mode 100644 index 000000000..32267d93e --- /dev/null +++ b/media_mygui/openmw_stats_window_layout.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media_mygui/openmw_text.skin.xml b/media_mygui/openmw_text.skin.xml index 874a5b804..6eb2bdfd4 100644 --- a/media_mygui/openmw_text.skin.xml +++ b/media_mygui/openmw_text.skin.xml @@ -1,17 +1,41 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/media_mygui/openmw_windows.skin.xml b/media_mygui/openmw_windows.skin.xml index 1c6a27cc9..ebb853f8d 100644 --- a/media_mygui/openmw_windows.skin.xml +++ b/media_mygui/openmw_windows.skin.xml @@ -2,7 +2,7 @@ - + @@ -63,49 +63,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -213,7 +170,7 @@ - + @@ -243,14 +200,30 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media_mygui/smallbars.png b/media_mygui/smallbars.png new file mode 100644 index 000000000..a9ed572ef Binary files /dev/null and b/media_mygui/smallbars.png differ diff --git a/media_mygui/transparent.png b/media_mygui/transparent.png new file mode 100644 index 000000000..32d2ed197 Binary files /dev/null and b/media_mygui/transparent.png differ diff --git a/monster/compiler/assembler.d b/monster/compiler/assembler.d index d4bd7ab4a..0852f7561 100644 --- a/monster/compiler/assembler.d +++ b/monster/compiler/assembler.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/block.d b/monster/compiler/block.d index c876cd568..a4cbe80fe 100644 --- a/monster/compiler/block.d +++ b/monster/compiler/block.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/bytecode.d b/monster/compiler/bytecode.d index 1f7af82d6..4635d29fc 100644 --- a/monster/compiler/bytecode.d +++ b/monster/compiler/bytecode.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/enums.d b/monster/compiler/enums.d index 321ebf84a..44095223a 100644 --- a/monster/compiler/enums.d +++ b/monster/compiler/enums.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/expression.d b/monster/compiler/expression.d index a918e4507..8125c792b 100644 --- a/monster/compiler/expression.d +++ b/monster/compiler/expression.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ @@ -811,32 +811,17 @@ class LiteralExpr : Expression return; } - bool hasPercent() - { - int i = value.str.find('%'); - if(i == -1) return false; - - // Make sure it is at the end - if(i != value.str.length-1) - fail("Number literals can only have a percentage sign (%) at the end. Perhaps you meant the reminder operator '%%' ?", value.loc); - - return true; - } - // Numeric literal. if(value.type == TT.NumberLiteral) { // Parse number strings. Simple hack for now, assume it's an // int unless it contains a period, then it's a float. TODO: // Improve this later, see how it is done elsewhere. - if(value.str.find('.') != -1 || hasPercent()) + if(value.str.find('.') != -1) { type = BasicType.getFloat; fval = atof(value.str); - if(hasPercent()) - fval /= 100; - return; } diff --git a/monster/compiler/functions.d b/monster/compiler/functions.d index 228c0c6b7..b9895b0de 100644 --- a/monster/compiler/functions.d +++ b/monster/compiler/functions.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/linespec.d b/monster/compiler/linespec.d index 080c93215..9d664cd8b 100644 --- a/monster/compiler/linespec.d +++ b/monster/compiler/linespec.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/operators.d b/monster/compiler/operators.d index 0257d1953..66e35e22a 100644 --- a/monster/compiler/operators.d +++ b/monster/compiler/operators.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/properties.d b/monster/compiler/properties.d index 1a8d3fcf4..b66f42a1a 100644 --- a/monster/compiler/properties.d +++ b/monster/compiler/properties.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/scopes.d b/monster/compiler/scopes.d index c6210a7b6..38890afcc 100644 --- a/monster/compiler/scopes.d +++ b/monster/compiler/scopes.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/statement.d b/monster/compiler/statement.d index 5b5da5110..4d53bdda1 100644 --- a/monster/compiler/statement.d +++ b/monster/compiler/statement.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/states.d b/monster/compiler/states.d index 253b331be..6105335f9 100644 --- a/monster/compiler/states.d +++ b/monster/compiler/states.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/structs.d b/monster/compiler/structs.d index 7772b938a..3ad6c447e 100644 --- a/monster/compiler/structs.d +++ b/monster/compiler/structs.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/tokenizer.d b/monster/compiler/tokenizer.d index f66ba8b2a..10d796d10 100644 --- a/monster/compiler/tokenizer.d +++ b/monster/compiler/tokenizer.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ @@ -43,7 +43,7 @@ bool validIdentChar(char c) } // Same as above, except numbers are not allowed as the first -// character. Will extend to support UTF8 later. +// character. Will extend to support full Unicode later. bool validFirstIdentChar(char c) { if((c >= 'a' && c <= 'z') || @@ -104,7 +104,7 @@ enum TT Import, Clone, Override, Final, Function, With, This, New, Static, Const, Out, Ref, Abstract, Idle, Public, Private, Protected, True, False, Native, Null, - Goto, Var, In, + Goto, Var, Last, // Tokens after this do not have a specific string // associated with them. @@ -247,7 +247,6 @@ const char[][] tokenList = TT.Null : "null", TT.Goto : "goto", TT.Var : "var", - TT.In : "in", // These are only used in error messages TT.StringLiteral : "string literal", @@ -540,10 +539,6 @@ class StreamTokenizer // also explicitly allow '.' dots. int len = 1; bool lastDot = false; // Was the last char a '.'? - // I've tried with percentage literals (10% = 0.10), but it - // conflicts with the remainder division operator (which - // shouldn't change), so I've disabled it for now. - //bool lastPer = false; // Was it a '%'? foreach(char ch; line[1..$]) { if(ch == '.') @@ -557,19 +552,6 @@ class StreamTokenizer } lastDot = true; } - /* - else if(ch == '%') - { - // Ditto for percentage signs. We allow '%' but not - // '%%' - if(lastPer) - { - len--; - break; - } - lastPer = true; - } - */ else { if(!validIdentChar(ch)) break; diff --git a/monster/compiler/types.d b/monster/compiler/types.d index 9513193ff..2e5964c47 100644 --- a/monster/compiler/types.d +++ b/monster/compiler/types.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/compiler/variables.d b/monster/compiler/variables.d index e39bf3fb7..0f94900a5 100644 --- a/monster/compiler/variables.d +++ b/monster/compiler/variables.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/modules/all.d b/monster/modules/all.d index 9dab2d0d4..29a47dcaf 100644 --- a/monster/modules/all.d +++ b/monster/modules/all.d @@ -1,6 +1,31 @@ +/* + Monster - an advanced game scripting language + Copyright (C) 2007-2009 Nicolay Korslund + Email: + WWW: http://monster.snaptoad.com/ + + This file (all.d) is part of the Monster script language + package. + + Monster is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + module monster.modules.all; import monster.modules.io; +import monster.modules.math; import monster.modules.timer; import monster.modules.frames; import monster.modules.random; @@ -13,4 +38,5 @@ void initAllModules() initFramesModule(); initThreadModule(); initRandomModule(); + initMathModule(); } diff --git a/monster/modules/frames.d b/monster/modules/frames.d index 353a574e9..6944ca96d 100644 --- a/monster/modules/frames.d +++ b/monster/modules/frames.d @@ -1,3 +1,27 @@ +/* + Monster - an advanced game scripting language + Copyright (C) 2007-2009 Nicolay Korslund + Email: + WWW: http://monster.snaptoad.com/ + + This file (frames.d) is part of the Monster script language + package. + + Monster is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + // Provides some simple numbers and functions regarding the rendering // frames of the application. It's up to the user to some degree to diff --git a/monster/modules/io.d b/monster/modules/io.d index 4764ae0e0..e1f615e9e 100644 --- a/monster/modules/io.d +++ b/monster/modules/io.d @@ -1,9 +1,32 @@ +/* + Monster - an advanced game scripting language + Copyright (C) 2007-2009 Nicolay Korslund + Email: + WWW: http://monster.snaptoad.com/ + + This file (io.d) is part of the Monster script language + package. + + Monster is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + // This module provides simple output functions for Monster. The 'i' -// part (input) isn't really there yet. +// (input) part of 'io' isn't really there yet. module monster.modules.io; -import std.stdio; import monster.monster; const char[] moduleDef = @@ -16,6 +39,29 @@ native writelns(char[][] args...); native print(char[][] args...); "; //" +// Use tango library functions directly, since flushing the +// minibos-versions will give weird effects when mixing with other +// tango output. +version(Tango) +{ +import tango.io.Stdout; +void doWrite(bool space) +{ + AIndex[] args = stack.popAArray(); + + char[] form = "{}"; + if(space) form = "{} "; + + foreach(AIndex ind; args) + Stdout.format(form, arrays.getRef(ind).carr); + + Stdout.flush(); +} +void writefln() { Stdout.newline; } +} +else +{ // Phobos +import std.stdio; void doWrite(bool space) { AIndex[] args = stack.popAArray(); @@ -28,7 +74,7 @@ void doWrite(bool space) fflush(stdout); } - +} void initIOModule() { static MonsterClass mc; diff --git a/monster/modules/io.mn b/monster/modules/io.mn index 445b033ab..0bba29192 100644 --- a/monster/modules/io.mn +++ b/monster/modules/io.mn @@ -5,8 +5,13 @@ module io; +// Write to console, with or without a newline native write(char[][] args...); native writeln(char[][] args...); + +// Automatically inserts spaces between arguments native writes(char[][] args...); native writelns(char[][] args...); + +// Identical to writelns native print(char[][] args...); diff --git a/monster/modules/math.d b/monster/modules/math.d new file mode 100644 index 000000000..40477a05c --- /dev/null +++ b/monster/modules/math.d @@ -0,0 +1,165 @@ +/* + Monster - an advanced game scripting language + Copyright (C) 2007-2009 Nicolay Korslund + Email: + WWW: http://monster.snaptoad.com/ + + This file (math.d) is part of the Monster script language + package. + + Monster is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + + +// Simple math functions +module monster.modules.math; + +import monster.monster; +import std.math; + +const char[] moduleDef = +"module math; + +double E = 2.7182818284590452354; +double PI = 3.141592653589793238; +double DEGTORAD = 3.141592653590/180; +double RADTODEG = 180/3.141592653590; + +native double sin(double x); +native double cos(double x); +native double tan(double x); +native double asin(double x); +native double acos(double x); +native double atan(double x); +native double atan2(double y, double x); // = atan(y/x) +native double sinh(double x); +native double cosh(double x); +native double tanh(double x); +native double asinh(double x); +native double acosh(double x); +native double atanh(double x); + +native double sqrt(double x); +native double exp(double x); // e^x +native double exp2(double x); // 2^x +native double log(double x); // base e +native double log10(double x);// base 10 +native double log2(double x); // base 2 + +native double pow(double x, double y); // x^y +native double ipow(double x, int n); // x^n (faster than pow) + +native int abs(int x); +native double fabs(double x); +native double ceil(double x); +native double floor(double x); +native double round(double x); // rounds to nearest integer +native double trunc(double x); + +native double hypot(double x, double y); // = sqrt(x*x+y*y) +native double cbrt(double x); // cube root + +// Calculates polynomial a0 + x*a1 + x^2*a2 + x^3*a3 + ... +native double poly(double x, float[] A); +"; //" + +version(Tango) +{ + double fabs(double x) { return abs(x); } +} + +void initMathModule() +{ + static MonsterClass mc; + if(mc !is null) return; + + mc = new MonsterClass(MC.String, moduleDef, "math"); + + mc.bind("sin", { stack.pushDouble(sin(stack.popDouble)); }); + mc.bind("cos", { stack.pushDouble(cos(stack.popDouble)); }); + mc.bind("tan", { stack.pushDouble(tan(stack.popDouble)); }); + mc.bind("asin", { stack.pushDouble(asin(stack.popDouble)); }); + mc.bind("acos", { stack.pushDouble(acos(stack.popDouble)); }); + mc.bind("atan", { stack.pushDouble(atan(stack.popDouble)); }); + + mc.bind("sinh", { stack.pushDouble(sinh(stack.popDouble)); }); + mc.bind("cosh", { stack.pushDouble(cosh(stack.popDouble)); }); + mc.bind("tanh", { stack.pushDouble(tanh(stack.popDouble)); }); + mc.bind("asinh", { stack.pushDouble(asinh(stack.popDouble)); }); + mc.bind("acosh", { stack.pushDouble(acosh(stack.popDouble)); }); + mc.bind("atanh", { stack.pushDouble(atanh(stack.popDouble)); }); + + mc.bind("atan2", + { + // Remember to pop the variables in the reverse order + auto x = stack.popDouble; + stack.pushDouble(atan2(stack.popDouble, x)); + }); + + mc.bind("sqrt", { stack.pushDouble(sqrt(stack.popDouble)); }); + mc.bind("exp", { stack.pushDouble(exp(stack.popDouble)); }); + mc.bind("exp2", { stack.pushDouble(exp2(stack.popDouble)); }); + mc.bind("log", { stack.pushDouble(log(stack.popDouble)); }); + mc.bind("log2", { stack.pushDouble(log2(stack.popDouble)); }); + mc.bind("log10", { stack.pushDouble(log10(stack.popDouble)); }); + + mc.bind("pow", + { + auto x = stack.popDouble; + stack.pushDouble(pow(stack.popDouble, x)); + }); + mc.bind("ipow", + { + auto x = stack.popInt; + stack.pushDouble(pow(cast(real)stack.popDouble, x)); + }); + + mc.bind("abs", { stack.pushDouble(abs(stack.popDouble)); }); + mc.bind("fabs", { stack.pushDouble(fabs(stack.popDouble)); }); + mc.bind("ceil", { stack.pushDouble(ceil(stack.popDouble)); }); + mc.bind("floor", { stack.pushDouble(floor(stack.popDouble)); }); + mc.bind("round", { stack.pushDouble(round(stack.popDouble)); }); + mc.bind("trunc", { stack.pushDouble(trunc(stack.popDouble)); }); + + // Order doesn't matter here + mc.bind("hypot", { stack.pushDouble(hypot(stack.popDouble, + stack.popDouble)); }); + + mc.bind("cbrt", { stack.pushDouble(cbrt(stack.popDouble)); }); + + mc.bind("poly", &npoly); +} + +// Implement this ourselves, since phobos doesn't use the types we +// want +double poly(double x, float A[]) +{ + // Use 'real' internally for higher precision + real r = A[$-1]; + foreach_reverse(c; A[0..$-1]) + { + r *= x; + r += c; + } + return r; +} + +// double poly(double x, float[] A); +void npoly() +{ + auto arf = stack.popArray(); + assert(arf.elemSize == 1); + stack.pushDouble(poly(stack.popDouble, arf.farr)); +} diff --git a/monster/modules/math.mn b/monster/modules/math.mn new file mode 100644 index 000000000..eeb71923a --- /dev/null +++ b/monster/modules/math.mn @@ -0,0 +1,43 @@ +module math; + +double E = 2.7182818284590452354; +double PI = 3.141592653589793238; +double DEGTORAD = 3.141592653590/180; +double RADTODEG = 180/3.141592653590; + +native double sin(double x); +native double cos(double x); +native double tan(double x); +native double asin(double x); +native double acos(double x); +native double atan(double x); +native double atan2(double y, double x); // = atan(y/x) +native double sinh(double x); +native double cosh(double x); +native double tanh(double x); +native double asinh(double x); +native double acosh(double x); +native double atanh(double x); + +native double sqrt(double x); +native double exp(double x); // e^x +native double exp2(double x); // 2^x +native double log(double x); // base e +native double log10(double x);// base 10 +native double log2(double x); // base 2 + +native double pow(double x, double y); // x^y +native double ipow(double x, int n); // x^n (faster than pow) + +native int abs(int x); +native double fabs(double x); +native double ceil(double x); +native double floor(double x); +native double round(double x); // rounds to nearest integer +native double trunc(double x); + +native double hypot(double x, double y); // = sqrt(x*x+y*y) +native double cbrt(double x); // cube root + +// Calculates polynomial a0 + x*a1 + x^2*a2 + x^3*a3 + ... +native double poly(double x, float[] A); diff --git a/monster/modules/random.d b/monster/modules/random.d index 6d0173e7a..184b73c22 100644 --- a/monster/modules/random.d +++ b/monster/modules/random.d @@ -1,3 +1,25 @@ +/* + Monster - an advanced game scripting language + Copyright (C) 2007-2009 Nicolay Korslund + Email: + WWW: http://monster.snaptoad.com/ + + This file (random.d) is part of the Monster script language package. + + Monster is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ // This module provides simple random number generation. Since this is // intended for game development, speed and simplicity is favored over diff --git a/monster/modules/threads.d b/monster/modules/threads.d index fb5c0c05c..bef44ee7f 100644 --- a/monster/modules/threads.d +++ b/monster/modules/threads.d @@ -1,3 +1,27 @@ +/* + Monster - an advanced game scripting language + Copyright (C) 2007-2009 Nicolay Korslund + Email: + WWW: http://monster.snaptoad.com/ + + This file (threads.d) is part of the Monster script language + package. + + Monster is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + // This module provides an interface to the virtual threading API in // Monster. diff --git a/monster/modules/timer.d b/monster/modules/timer.d index 0ee82f19b..788ed7346 100644 --- a/monster/modules/timer.d +++ b/monster/modules/timer.d @@ -1,3 +1,27 @@ +/* + Monster - an advanced game scripting language + Copyright (C) 2007-2009 Nicolay Korslund + Email: + WWW: http://monster.snaptoad.com/ + + This file (timer.d) is part of the Monster script language + package. + + Monster is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + // This module contains (or will contain) various routines for // timing. It is also home of the ubiquitous "sleep" idle function. diff --git a/monster/modules/timer.mn b/monster/modules/timer.mn index f613e0883..2afb9b62c 100644 --- a/monster/modules/timer.mn +++ b/monster/modules/timer.mn @@ -4,4 +4,6 @@ */ singleton timer; + +// Sleep the given number of seconds idle sleep(float secs); diff --git a/monster/monster.d b/monster/monster.d index 399d892f9..dc81f1c2a 100644 --- a/monster/monster.d +++ b/monster/monster.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/util/aa.d b/monster/util/aa.d index e750b7995..adefce0c0 100644 --- a/monster/util/aa.d +++ b/monster/util/aa.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/util/flags.d b/monster/util/flags.d index e581d6cfa..7fe8964b0 100644 --- a/monster/util/flags.d +++ b/monster/util/flags.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/util/freelist.d b/monster/util/freelist.d index b41c9f9c9..0037cb402 100644 --- a/monster/util/freelist.d +++ b/monster/util/freelist.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/util/growarray.d b/monster/util/growarray.d index b3ae52e07..d11df9291 100644 --- a/monster/util/growarray.d +++ b/monster/util/growarray.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/util/list.d b/monster/util/list.d index a9cd393f2..5d0ddfb09 100644 --- a/monster/util/list.d +++ b/monster/util/list.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/util/string.d b/monster/util/string.d index 999f200e3..624bdf821 100644 --- a/monster/util/string.d +++ b/monster/util/string.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2004, 2007, 2008 Nicolay Korslund + Copyright (C) 2004, 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/arrays.d b/monster/vm/arrays.d index b0c938e19..00d578c4f 100644 --- a/monster/vm/arrays.d +++ b/monster/vm/arrays.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/codestream.d b/monster/vm/codestream.d index 00bb4707f..dbcca1a9f 100644 --- a/monster/vm/codestream.d +++ b/monster/vm/codestream.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/error.d b/monster/vm/error.d index 268d5413f..5b4a72739 100644 --- a/monster/vm/error.d +++ b/monster/vm/error.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/fstack.d b/monster/vm/fstack.d index 4b498e122..ec22d8201 100644 --- a/monster/vm/fstack.d +++ b/monster/vm/fstack.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/gc.d b/monster/vm/gc.d index 8c0429fc4..f640da76f 100644 --- a/monster/vm/gc.d +++ b/monster/vm/gc.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/idlefunction.d b/monster/vm/idlefunction.d index 21aa00c85..fce8a6bb7 100644 --- a/monster/vm/idlefunction.d +++ b/monster/vm/idlefunction.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/iterators.d b/monster/vm/iterators.d index 344747ce9..0bea13bfa 100644 --- a/monster/vm/iterators.d +++ b/monster/vm/iterators.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/mclass.d b/monster/vm/mclass.d index 6d1b2e045..a840132e7 100644 --- a/monster/vm/mclass.d +++ b/monster/vm/mclass.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/mobject.d b/monster/vm/mobject.d index e8e396250..c36b8365b 100644 --- a/monster/vm/mobject.d +++ b/monster/vm/mobject.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/params.d b/monster/vm/params.d index 752cb5829..87850204d 100644 --- a/monster/vm/params.d +++ b/monster/vm/params.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/stack.d b/monster/vm/stack.d index 8a872b248..05fd105be 100644 --- a/monster/vm/stack.d +++ b/monster/vm/stack.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/monster/vm/thread.d b/monster/vm/thread.d index d80f45271..f3a3baab6 100644 --- a/monster/vm/thread.d +++ b/monster/vm/thread.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ @@ -47,11 +47,11 @@ import monster.vm.iterators; import monster.vm.error; import monster.vm.fstack; +import std.math : floor; + // Used for array copy below. It handles overlapping data for us. extern(C) void* memmove(void *dest, void *src, size_t n); -extern(C) double floor(double d); - import monster.util.list; alias _lstNode!(Thread) _tmp1; alias __FreeNode!(Thread) _tmp2; diff --git a/monster/vm/vm.d b/monster/vm/vm.d index 90f8e5f4e..779e1c206 100644 --- a/monster/vm/vm.d +++ b/monster/vm/vm.d @@ -1,6 +1,6 @@ /* Monster - an advanced game scripting language - Copyright (C) 2007, 2008 Nicolay Korslund + Copyright (C) 2007-2009 Nicolay Korslund Email: WWW: http://monster.snaptoad.com/ diff --git a/mscripts/fpsticker.mn b/mscripts/fpsticker.mn index 443a62213..2c7c40dc1 100644 --- a/mscripts/fpsticker.mn +++ b/mscripts/fpsticker.mn @@ -1,38 +1,36 @@ // Small script that prints the FPS to screen with regular intervals. -class FPSTicker; - import frames; -// Set the FPS widget text -native setText(char[][] args...); - -run() -{ - // Sleep one frame. This makes sure that we won't start running until - // the rendering begins. Not critically important, but it prevents the - // first printed value from being 'nan'. - fsleep(1); +// Set up the text widget +Widget txt = gui.text("StaticText", + gui.getWidth()-90, 10, 120, 30, + "Statistic"); +txt.setNeedMouseFocus(false); +txt.setTextColor(1,1,1); +txt.setCaption("hello!"); - setText("hello!"); +// Sleep one frame. This makes sure we only start running after +// rendering begins. It prevents the first printed value from being +// 'nan' +fsleep(1); - // counter and totalTime (in the 'frames' module) are updated - // automatically by the system. - ulong lastFrame = counter; - float lastTime = totalTime; +// counter and totalTime (in the 'frames' module) are updated +// automatically by the system. +ulong lastFrame = counter; +float lastTime = totalTime; - float delay = 1.5; +float delay = 1.5; - while(true) - { - sleep(delay); +while(true) +{ + sleep(delay); - // Calculate differences since last frame - ulong fdiff = counter-lastFrame; - float tdiff = totalTime-lastTime; + // Calculate differences since last frame + ulong fdiff = counter-lastFrame; + float tdiff = totalTime-lastTime; - setText("fps: ", fdiff / tdiff); + txt.setCaption("fps: ", fdiff/tdiff); - lastFrame = counter; - lastTime = totalTime; - } + lastFrame = counter; + lastTime = totalTime; } diff --git a/mscripts/gui/makegui.mn b/mscripts/gui/makegui.mn new file mode 100644 index 000000000..334e0a783 --- /dev/null +++ b/mscripts/gui/makegui.mn @@ -0,0 +1,5 @@ +/* +Widget hud; +hud = gui.loadLayout("openmw_hud_layout.xml"); +hud.setCoord(10,10,500,500); +*/ diff --git a/mscripts/gui/module/gui.mn b/mscripts/gui/module/gui.mn new file mode 100644 index 000000000..a452fa524 --- /dev/null +++ b/mscripts/gui/module/gui.mn @@ -0,0 +1,11 @@ +// GUI module. Only covers some very basic functions. +module gui; + +// Later, we'll have singleton gui : Widget; with most of the +// functions defined in Widget. + +native Widget loadLayout(char[] file); +native Widget text(char[] skin, int x, int y, int w, int h, + char[] layer); +native int getWidth(); +native int getHeight(); diff --git a/mscripts/gui/module/widget.mn b/mscripts/gui/module/widget.mn new file mode 100644 index 000000000..4f9df5860 --- /dev/null +++ b/mscripts/gui/module/widget.mn @@ -0,0 +1,10 @@ +class Widget; + +native setNeedMouseFocus(bool b); +native setTextColor(float r, float g, float b); +native setCoord(int x, int y, int w, int h); + +native setCaption(char[][] str...); + +// Find a named child widget +native Widget get(char[] name); diff --git a/mscripts/setup.d b/mscripts/setup.d index d0f652090..cb500f33e 100644 --- a/mscripts/setup.d +++ b/mscripts/setup.d @@ -28,7 +28,7 @@ import monster.compiler.scopes : global; import monster.modules.timer; import core.config; -import ogre.bindings; +import ogre.gui; import std.string; @@ -50,24 +50,20 @@ void initMonsterScripts() // Get the Config singleton object config.mo = (new MonsterClass("Config")).getSing(); - // Run the fps ticker - //vm.run("fpsticker.mn"); - auto mc = new MonsterClass("fpsticker.mn"); - mc.bind("setText", &setFpsText); - mc.createObject().call("run"); + // Set up the GUI Monster module + setupGUIScripts(); // Run the test script vm.run("test.mn"); } -void setFpsText() +// Run the GUI scripts. These should be run only after the +// GUI/rendering system has been initialized +void runGUIScripts() { - AIndex[] args = stack.popAArray(); - - char[] res; + // Create the HUD and windows + vm.run("makegui.mn"); - foreach(AIndex ind; args) - res ~= format("%s", arrays.getRef(ind).carr); - - gui_setFpsText(res.ptr); + // Run the fps ticker + vm.run("fpsticker.mn"); } diff --git a/ogre/bindings.d b/ogre/bindings.d index 6542ccef8..49121b2c0 100644 --- a/ogre/bindings.d +++ b/ogre/bindings.d @@ -163,7 +163,27 @@ void ogre_moveCameraRel(float x, float y, float z); // Insert a raw RGBA image into the texture system. //void ogre_insertTexture(char *name, int width, int height, void *data); -// Test +// GUI functions. Under development. +typedef void* WidgetPtr; void gui_setupGUI(); void gui_toggleGui(); -void gui_setFpsText(char *str); +void gui_setCellName(char *str); + +// Get the widget type, as a string +char *gui_widgetType(WidgetPtr); + +// Get the height or width of a widget. If the argument is null, +// return the size of the screen. +int gui_getHeight(WidgetPtr); +int gui_getWidth(WidgetPtr); + +// Set various properties of a given widget +void gui_setCaption(WidgetPtr, char*); +void gui_setNeedMouseFocus(WidgetPtr, int); +void gui_setTextColor(WidgetPtr, float,float,float); +void gui_setCoord(WidgetPtr, int,int,int,int); + +// Various ways to get or create widgets +WidgetPtr gui_loadLayout(char *file, char *prefix, WidgetPtr parent); +WidgetPtr gui_getChild(WidgetPtr, char*); +WidgetPtr gui_createText(char *skin, int x, int y, int w, int h, char *layer); diff --git a/ogre/cpp_mygui.cpp b/ogre/cpp_mygui.cpp index 200aadc7a..25a5dfcfe 100644 --- a/ogre/cpp_mygui.cpp +++ b/ogre/cpp_mygui.cpp @@ -1,37 +1,82 @@ -MyGUI::WidgetPtr FPSText; +// TODO: KILLME +char *cellName; +extern "C" void gui_setCellName(char *str) +{ + cellName = str; +} -MyGUI::WindowPtr mwindow; +// Get the widget type, as a string +extern "C" const char *gui_widgetType(MyGUI::WidgetPtr p) +{ return p->getTypeName().c_str(); } -OIS::MouseState state; +extern "C" int32_t gui_getHeight(MyGUI::WidgetPtr p) +{ + if(p == NULL) mWindow->getHeight(); + return p->getHeight(); +} -extern "C" void gui_toggleGui() +extern "C" int32_t gui_getWidth(MyGUI::WidgetPtr p) { - if(guiMode == 1) - { - guiMode = 0; - mGUI->hidePointer(); - if(mwindow) - mwindow->setVisible(false); - state = mMouse->getMouseState(); - } - else - { - // Restore the GUI mouse position. This is a hack because silly - // OIS doesn't allow us to set the mouse position ourselves. - *((OIS::MouseState*)&(mMouse->getMouseState())) = state; - mGUI->injectMouseMove(state.X.abs, state.Y.abs, 0); + if(p == NULL) return mWindow->getWidth(); + return p->getWidth(); +} - guiMode = 1; - mGUI->showPointer(); - if(mwindow) - mwindow->setVisible(true); - } +// Set various properties of a given widget +extern "C" void gui_setCaption(MyGUI::WidgetPtr p, char* s) +{ p->setCaption(s); } + +extern "C" void gui_setNeedMouseFocus(MyGUI::WidgetPtr p, int32_t b) +{ p->setNeedMouseFocus(b); } + +extern "C" void gui_setTextColor(MyGUI::WidgetPtr p, float r,float g,float b) +{ p->setTextColour(Ogre::ColourValue(b,g,r)); } + +extern "C" void gui_setCoord(MyGUI::WidgetPtr p, + int32_t x,int32_t y,int32_t w,int32_t h) +{ p->setCoord(x,y,w,h); } + +// Various ways to get or create widgets +extern "C" MyGUI::WidgetPtr gui_loadLayout(char *file, char *prefix, + MyGUI::WidgetPtr parent) +{ + // Get the list of Widgets in this layout + MyGUI::VectorWidgetPtr wlist; + wlist = MyGUI::LayoutManager::getInstance(). + loadLayout(file, prefix, parent); + + MyGUI::VectorWidgetPtr::iterator iter; + iter = wlist.begin(); + + // Return null if the list is empty + if(wlist.end() == iter) + return NULL; + + MyGUI::WidgetPtr res = *iter; + + ++iter; + + if(iter != wlist.end()) + std::cout << "WARNING: Layout '" << file + << "' has more than one root widget. Ignored.\n"; + + return res; } -void turnGuiOff(MyGUI::WidgetPtr sender) +extern "C" MyGUI::WidgetPtr gui_getChild(MyGUI::WidgetPtr p, char* name) { - guiMode = 1; - gui_toggleGui(); + return p->findWidget(name); +} + +extern "C" MyGUI::WidgetPtr gui_createText(const char *skin, + int32_t x, int32_t y, + int32_t w, int32_t h, + const char *layer) +{ + return mGUI->createWidget + (skin, + x,y,w,h, + MyGUI::ALIGN_LEFT | MyGUI::ALIGN_TOP, + layer); } // Copied from MyGUI demo code, with a few modifications @@ -110,11 +155,37 @@ public: mMainWidget->setCoord(x,y,w,h); } + void setVisible(bool b) + { + mMainWidget->setVisible(b); + } + virtual ~Layout() { shutdown(); } + void setText(const char* name, const char* caption) + { + MyGUI::WidgetPtr pt; + getWidget(pt, name); + pt->setCaption(caption); + } + + void setColor(const char* name, float r, float g, float b) + { + MyGUI::WidgetPtr pt; + getWidget(pt, name); + pt->setTextColour(Ogre::ColourValue(b,g,r)); + } + + void setImage(const char* name, const char* imgName) + { + MyGUI::StaticImagePtr pt; + getWidget(pt, name); + pt->setImageTexture(imgName); + } + protected: MyGUI::WidgetPtr mMainWidget; @@ -197,7 +268,135 @@ public: MyGUI::StaticImagePtr compass; }; +class MapWindow : public Layout +{ +public: + MapWindow() + : Layout("openmw_map_window_layout.xml") + { + setCoord(500,0,320,300); + mMainWidget->setCaption(cellName); + setText("WorldButton", "World"); + setColor("WorldButton", 0.75, 0.6, 0.35); + setImage("Compass", "compass.dds"); + } +}; + +class MainMenu : public Layout +{ +public: + MainMenu() + : Layout("openmw_mainmenu_layout.xml") + { + setCoord(0,0, + mWindow->getWidth(), + mWindow->getHeight()); + } +}; + +class StatsWindow : public Layout +{ +public: + void setBar(const char* name, const char* tname, int val, int max) + { + MyGUI::ProgressPtr pt; + getWidget(pt, name); + pt->setProgressRange(max); + pt->setProgressPosition(val); + + std::stringstream out; + out << val << "/" << max; + setText(tname, out.str().c_str()); + } + + StatsWindow() + : Layout("openmw_stats_window_layout.xml") + { + setCoord(0,0,498, 342); + mMainWidget->setCaption("Playername"); + + setText("Health_str", "Health"); + setText("Magicka_str", "Magicka"); + setText("Fatigue_str", "Fatigue"); + + setText("Level_str", "Level"); + setText("Race_str", "Race"); + setText("Class_str", "Class"); + + setText("LevelText", "5"); + setText("RaceText", "Wood Elf"); + setText("ClassText", "Pilgrim"); + + setBar("HBar", "HBarT", 60, 100); + setBar("MBar", "MBarT", 30, 100); + setBar("FBar", "FBarT", 80, 100); + + setText("Attrib1", "Strength"); + setText("Attrib2", "Intelligence"); + setText("Attrib3", "Willpower"); + setText("Attrib4", "Agility"); + setText("Attrib5", "Speed"); + setText("Attrib6", "Endurance"); + setText("Attrib7", "Personality"); + setText("Attrib8", "Luck"); + + setText("AttribVal1", "30"); + setText("AttribVal2", "40"); + setText("AttribVal3", "30"); + setText("AttribVal4", "75"); + setText("AttribVal5", "50"); + setText("AttribVal6", "40"); + setText("AttribVal7", "50"); + setText("AttribVal8", "40"); + } +}; + HUD *hud; +StatsWindow *stats; +MapWindow *map; +MyGUI::WidgetPtr FPSText; +MyGUI::WindowPtr mwindow; +OIS::MouseState state; + +// KILLME +extern "C" void gui_toggleGui() +{ + if(guiMode == 1) + { + guiMode = 0; + mGUI->hidePointer(); + if(mwindow) + mwindow->setVisible(false); + if(stats) + stats->setVisible(false); + if(map) + map->setVisible(false); + state = mMouse->getMouseState(); + } + else + { + // Restore the GUI mouse position. This is a hack because silly + // OIS doesn't allow us to set the mouse position ourselves. + *((OIS::MouseState*)&(mMouse->getMouseState())) = state; + mGUI->injectMouseMove(state.X.abs, state.Y.abs, 0); + + guiMode = 1; + mGUI->showPointer(); + if(mwindow) + mwindow->setVisible(true); + if(stats) + stats->setVisible(true); + if(map) + map->setVisible(true); + } +} + +// KILLME +void turnGuiOff(MyGUI::WidgetPtr sender) +{ + guiMode = 1; + gui_toggleGui(); +} extern "C" void gui_setupGUI() { @@ -209,29 +408,19 @@ extern "C" void gui_setupGUI() int mWidth = mWindow->getWidth(); int mHeight = mWindow->getHeight(); - int width = 120; - int height = 30; - - // FPS Ticker - FPSText = mGUI->createWidget - ("StaticText", - mWidth - width -10, 10, // Position - width, height, // Size - MyGUI::ALIGN_RIGHT | MyGUI::ALIGN_TOP, - "Statistic"); - FPSText->setTextAlign(MyGUI::ALIGN_RIGHT); - FPSText->setNeedMouseFocus(false); - FPSText->setTextColour(Ogre::ColourValue::White); + stats = new StatsWindow(); + map = new MapWindow(); + + /* // Window with Morrowind skin mwindow = mGUI->createWidget ("MW_Window", - (mWidth-width)/4, (mHeight-height)/4, // Position - 300, 190, // Size + (mWidth-width)/2, (mHeight-height)/2, // Position + 400, 190, // Size MyGUI::ALIGN_DEFAULT, "Windows"); mwindow->setCaption("Skin test"); mwindow->setMinSize(120, 140); - mwindow->getClientWidget()->setAlpha(0.6); MyGUI::WidgetPtr tmp; tmp = mwindow->createWidget @@ -242,23 +431,23 @@ extern "C" void gui_setupGUI() "MWButton1"); tmp->setCaption("Close"); tmp->eventMouseButtonClick = MyGUI::newDelegate(&turnGuiOff); - tmp->setInheritsAlpha(false); tmp = mwindow->createWidget ("DaedricText_orig", - 10,70, - 300, 20, + 20,80, + 500, 30, MyGUI::ALIGN_LEFT | MyGUI::ALIGN_TOP, "Daed1"); tmp->setCaption("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); tmp = mwindow->createWidget ("DaedricText", - 10,100, - 300, 20, + 20,130, + 500, 30, MyGUI::ALIGN_LEFT | MyGUI::ALIGN_TOP, "Daed2"); tmp->setCaption("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + */ // Turn the GUI off at startup turnGuiOff(NULL); @@ -266,8 +455,7 @@ extern "C" void gui_setupGUI() state.X.abs = mWidth / 2; state.Y.abs = mHeight / 2; - MyGUI::ProgressPtr prog; - + //* // Set up the HUD hud = new HUD(); @@ -281,10 +469,7 @@ extern "C" void gui_setupGUI() hud->setSpellStatus(65, 100); hud->setEffect("icons\\s\\tx_s_chameleon.dds"); -} + //*/ -extern "C" void gui_setFpsText(char *str) -{ - if(FPSText != NULL) - FPSText->setCaption(str); + //new MainMenu(); } diff --git a/ogre/gui.d b/ogre/gui.d new file mode 100644 index 000000000..6c6336db4 --- /dev/null +++ b/ogre/gui.d @@ -0,0 +1,255 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008-2009 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.snaptoad.com/ + + This file (gui.d) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + +module ogre.gui; + +import monster.monster; +import ogre.bindings; +import std.string; + +// Widget class and gui module +MonsterClass + gmc, // GUI module + wid_mc, // Widget + but_mc, // Button + tex_mc, // StaticText + img_mc, // StaticImage + pro_mc, // Progress + win_mc; // Window + +MWidget[WidgetPtr] gui_store; + +class MWidget +{ + WidgetPtr widget; + MonsterObject *mo; + + // Used for layouts + bool isLayout; + char[] prefix; + + // For layouts + this(char[] layout, WidgetPtr parent = null) + { + assert(layout.length); + + isLayout = true; + prefix = format("%s", cast(void*)this); + + widget = gui_loadLayout(layout.ptr, prefix.ptr, parent); + if(widget is null) + fail("Layout " ~ layout ~ " is empty"); + + this(); + } + + // For normal widgets + this(WidgetPtr w) + { + isLayout = false; + widget = w; + assert(widget !is null); + this(); + } + + private this() + { + assert(widget !is null); + + // Create the object from the right class + mo = toClass(widget).createObject(); + // But store the pointer in the Widget's pointer slot + mo.getExtra(wid_mc).obj = this; + // Also store a lookup for later + gui_store[widget] = this; + } + + MWidget getChild(char[] name) + { + if(prefix.length) + name = prefix ~ name; + + // Get the child widget + auto pt = gui_getChild(widget, name.ptr); + + if(pt is null) + fail("Widget has no child named " ~ name); + + // Return the MWidget + return get(pt); + } + + // Return the MonsterClass corresponding to a given widget. + private static MonsterClass toClass(WidgetPtr p) + { + switch(widgetType(p)) + { + /* + case "Button": return but_mc; + case "StaticText": return tex_mc; + case "StaticImage": return img_mc; + case "Progress": return pro_mc; + case "Window": return win_mc; + */ + default: + // Use "Widget" for all unimplemented types + case "Widget": return wid_mc; + } + } + + // Get the MWidget (and associatied MonsterObject) corresponding to + // a given Widget. + static MWidget get(WidgetPtr wid) + { + // First, check if the instance exists + auto p = wid in gui_store; + if(p) return *p; + + // No MWidget exists. We have to create one. + return new MWidget(wid); + } +}; + +char[] widgetType(WidgetPtr p) +{ + return toString(gui_widgetType(p)); +} + +MWidget getMWOwner(MonsterObject *mo) +{ + return (cast(MWidget)mo.getExtra(wid_mc).obj); +} +MWidget getMWOwner() +{ + return getMWOwner(params.obj()); +} +WidgetPtr getOwner(MonsterObject *mo) +{ + return getMWOwner(mo).widget; +} +WidgetPtr getOwner() +{ + return getMWOwner().widget; +} + +// Widget functions +void setCaption() +{ + AIndex[] args = stack.popAArray(); + + char[] res; + + foreach(AIndex ind; args) + res ~= format("%s", arrays.getRef(ind).carr); + + gui_setCaption(getOwner(), res.ptr); +} +void setNeedMouseFocus() +{ gui_setNeedMouseFocus(getOwner(), stack.popBool); } +void setTextColor() +{ + float b = stack.popFloat(); + float g = stack.popFloat(); + float r = stack.popFloat(); + gui_setTextColor(getOwner(), r,g,b); +} +void setCoord() +{ + int h = stack.popInt(); + int w = stack.popInt(); + int y = stack.popInt(); + int x = stack.popInt(); + gui_setCoord(getOwner(), x,y,w,h); +} + +void get() +{ + // Get the owner MWidget + auto mw = getMWOwner(); + // Get the child + mw = mw.getChild(stack.popString8()); + // Push the object + stack.pushObject(mw.mo); +} + +// TODO: These are all written to be used with the 'gui' module. Later +// they should be part of Widget, and create child widgets. When used +// with 'gui' they create root widgets. + +void loadLayout() +{ + MWidget mw = new MWidget(stack.popString8()); + stack.pushObject(mw.mo); +} + +void text() +{ + char[] layer = stack.popString8(); + int h = stack.popInt(); + int w = stack.popInt(); + int y = stack.popInt(); + int x = stack.popInt(); + char[] skin = stack.popString8(); + WidgetPtr ptr = gui_createText(skin.ptr, + x,y,w,h, + layer.ptr); + assert(widgetType(ptr) == "StaticText"); + MWidget mw = new MWidget(ptr); + stack.pushObject(mw.mo); +} + +void getWidth() +{ + stack.pushInt(gui_getWidth(null)); +} + +void getHeight() +{ + stack.pushInt(gui_getHeight(null)); +} + +void setupGUIScripts() +{ + vm.addPath("mscripts/gui/"); + vm.addPath("mscripts/gui/module/"); + gmc = new MonsterClass("gui", "gui.mn"); + wid_mc = new MonsterClass("Widget", "widget.mn"); + /* + but_mc = new MonsterClass("Button", "button.mn"); + tex_mc = new MonsterClass("Text", "text.mn"); + img_mc = new MonsterClass("Image", "image.mn"); + pro_mc = new MonsterClass("Progress", "progress.mn"); + win_mc = new MonsterClass("Window", "window.mn"); + */ + + wid_mc.bind("setCaption", &setCaption); + wid_mc.bind("setNeedMouseFocus", &setNeedMouseFocus); + wid_mc.bind("setTextColor", &setTextColor); + wid_mc.bind("setCoord", &setCoord); + wid_mc.bind("get", &get); + + gmc.bind("text", &text); + gmc.bind("loadLayout", &loadLayout); + gmc.bind("getWidth", &getWidth); + gmc.bind("getHeight", &getHeight); +} diff --git a/ogre/ogre.d b/ogre/ogre.d index ce6b3225b..4df7383d8 100644 --- a/ogre/ogre.d +++ b/ogre/ogre.d @@ -1,6 +1,6 @@ /* OpenMW - The completely unofficial reimplementation of Morrowind - Copyright (C) 2008 Nicolay Korslund + Copyright (C) 2008-2009 Nicolay Korslund Email: < korslund@gmail.com > WWW: http://openmw.snaptoad.com/ @@ -27,6 +27,8 @@ import core.resource; import core.config; import ogre.bindings; +import mscripts.setup; + import bullet.bindings; import util.uniquename; import std.stdio; @@ -116,9 +118,12 @@ void setupOgre() // exterior cells differently, etc. ogre_makeScene(); - // Load the GUI elements + // Load the GUI system gui_setupGUI(); + // Run the GUI scripts + runGUIScripts(); + ogreSetup = true; } diff --git a/openmw.d b/openmw.d index f81effb24..00458bf7a 100644 --- a/openmw.d +++ b/openmw.d @@ -224,6 +224,10 @@ void main(char[][] args) return null; } + if(cd.inCell !is null) + // Set the name for the GUI (temporary hack) + gui_setCellName(cd.inCell.id.ptr); + if(render) { // Warm up OGRE