Commit Graph

874 Commits (master)

Author SHA1 Message Date
Sven Eberhardt 8a5dbdc73f Qt Editor: More shape prop storage options 2016-05-23 19:22:49 -04:00
Nicolas Hake 3fd1187833 Don't overload CompileNewFunc with rvalue reference parameters
We don't need to pass the C4ValueNumbers* as a rvalue reference, and
doing so needs const qualifiers on MSVC.
2016-05-21 12:56:57 +02:00
Günther Brammer d23ffde361 Merge script branch 2016-05-15 19:21:26 +02:00
Günther Brammer 6763f2b5c7 Silence complaints about missing functions in EffectCall (#1736)
All the other effect callbacks silently ignored missing functions, either
by using the Call variant that doesn't complain about it, or checking for
the missing function themselves.
2016-05-15 19:20:43 +02:00
Günther Brammer 0559a93f88 Script: CreateEffect effects do not get their target in callbacks
They can use the Target property instead.
2016-05-15 15:20:08 +02:00
Günther Brammer 3aa6978c4e Script: Effects have their target as a property "Target" 2016-05-15 15:17:18 +02:00
Günther Brammer c0d32f8f4e Remove redundant target parameters from effect implementation 2016-05-15 15:17:17 +02:00
Günther Brammer 6aaf7cd2ef Store a pointer to the effect target in the effect itself 2016-05-15 15:17:17 +02:00
Günther Brammer 408ac90cd7 Scenario effects: Use Scenario and not Scenario->GetPrototype() as this() 2016-05-15 15:17:17 +02:00
Günther Brammer f927717458 CreateEffect initializes the name of the new effect
Effects with prototypes were supposed to inherit their names from the
prototype, but the effect prototypes are also supposed to get their names
from ParentKeyName, which is not inherited. Maybe that'll change, but for
now this matches how old effects work.
2016-05-15 15:17:17 +02:00
Günther Brammer 5c6a805fd5 Add move constructor to C4Value 2016-05-15 15:17:17 +02:00
Günther Brammer 9e8d644a26 StdAdaptors: Make mkParAdapt(mkPtrAdaptNoNull(), Par1, Par2) work
Employ variadic template arguments and more rvalue references for this.
Sadly, StdParameterAdapt itself is even more complicated, since it has to
store the parameters instead of just forwarding them, so the limit is still
two parameters. But that's twice as much as before in many cases.
2016-05-14 22:59:59 +02:00
Nicolas Hake 511e3bbb36 Aul: Deprecate implicit conversion from 0 to object/proplist/def/string
Instead of (int)0, nil should be used to signify "no object" etc.
2016-05-13 16:28:45 +02:00
Nicolas Hake 370a1dd3d1 Aul: Re-enable parameter type checking after AST rewrite 2016-05-13 16:22:37 +02:00
Nicolas Hake 3217fbf55b C4AulScriptFunc::AddPar: Accept type in addition to name
This way, we don't have to first add the parameter and then set the type
afterwards via internal members.
2016-05-13 16:22:00 +02:00
Nicolas Hake eca8f2cce8 Aul: && returns either parameter, not bool 2016-05-13 16:20:17 +02:00
Nicolas Hake 43c6f946dd Aul: Split assignment op from standard BinOp
Assignment was special-cased everywhere, so it can just as well get a
separate AST node.
2016-05-13 13:50:29 +02:00
Nicolas Hake daf3424e63 Delete some commented-out legacy function parameters 2016-05-13 13:14:23 +02:00
Nicolas Hake 092a23c2f7 Aul: Parse scripts into an AST, then generate bytecode from that
This commit contains a fairly substantial rewrite of the C4Script code
generator. Instead of generating bytecode while parsing the script,
we're now parsing the script into a syntax tree, and have any further
processing happen on that instead of the raw source.

At this time, the code generator emits the same bytecode as the old
parser; there are several optimization opportunities that arise from the
new possibility to emit code out of order from its specification by the
author.

Compared to the old compiler, this one is still rather deficient when
dealing with incorrect code; it's also not emitting several warnings
that used to be diagnosed.
2016-05-12 19:43:48 +02:00
Nicolas Hake 78e5f8528d C4PropList::GetParent: make const 2016-05-12 18:47:53 +02:00
Nicolas Hake 5872b5e8ae C4AulFunc::GetFullName: make const 2016-05-11 17:15:47 +02:00
Nicolas Hake 10abb1bbdb Remove unused C4AUL_CodeBufSize 2016-05-11 17:15:47 +02:00
Nicolas Hake a100b93e7f DEBUG_BYTECODE_DUMP: Allow setting from build system 2016-05-11 17:15:47 +02:00
Nicolas Hake 16641d3841 C4AulScriptFunc::DumpByteCode: properly align BCC names
The old code just appended eight spaces when the type of the BCC was
shorter than eight chars.
2016-05-11 17:15:47 +02:00
Nicolas Hake 26334cb4d7 Aul: Join AB_INT + AB_Neg 2016-05-09 12:33:59 +02:00
Nicolas Hake 34556e3e81 Aul: Join AB_STRING+AB_ARRAYA to AB_PROP 2016-05-09 12:33:58 +02:00
Nicolas Hake 33f7fb935f C4AulCompiler: Rename iStack to stack_height 2016-05-09 12:33:51 +02:00
Nicolas Hake 41000a8f9a C4AulCompiler: Rename pLoopStack to active_loops 2016-05-09 12:21:33 +02:00
Nicolas Hake d0dbe05876 C4AulCompiler: Rename fJump to at_jump_target
You have no idea how much I hate systems hungarian.
2016-05-09 12:21:33 +02:00
Nicolas Hake f0b4ef46a5 GetStackValue: Remove "default: /* unreachable */"
Without an explicit default case, the compiler can warn about unhandled
enum values inside the switch.
2016-05-09 12:21:33 +02:00
Nicolas Hake 7a135a060f C4AulParse: Take GetTokenName out of public interface 2016-05-09 12:21:33 +02:00
Nicolas Hake 0a3b31e735 C4AulParse::AddVarAccess: Move to C4AulCompiler 2016-05-09 12:21:33 +02:00
Nicolas Hake 0342711cd4 C4AulCompiler: Take GetStackValue out of public interface 2016-05-09 12:21:33 +02:00
Nicolas Hake 792e12adad C4AulCompiler: Split into separate file 2016-05-09 12:21:33 +02:00
Nicolas Hake c8d71d47c0 C4CodeGen: Rename to C4AulCompiler
I need to split up C4CodeGen into smaller parts, and having the bit that
actually generates the bytecode named C4CodeGenCodeGen would be silly.
2016-05-09 12:21:33 +02:00
Günther Brammer 69427a484a C4AulParse: Check for function names after '->' with the helper function 2016-05-05 02:47:17 +02:00
Günther Brammer 994cb52cea C4AulParse: Don't escape spaces in bytecode dumps of strings 2016-05-05 02:38:36 +02:00
Günther Brammer 99f704fbb8 Script: Prevent writes to constant arrays 2016-05-05 02:10:41 +02:00
Günther Brammer 9741af42fd Replace all usages of the old local variables list with properties 2016-05-01 00:28:37 +02:00
Günther Brammer 7792acdff0 Script: Check for functions before keywords
This unifies the lookup for local variables and functions. Its slightly
awkward that global functions can overload if and Par now, but local
variables already could.
2016-05-01 00:28:37 +02:00
Günther Brammer 30f7457d89 Remove unused macros leftover from removed script features 2016-05-01 00:28:37 +02:00
Günther Brammer b8f2d0ca87 Script: Repeat the parser error message when executing a broken function 2016-05-01 00:28:37 +02:00
Günther Brammer 17b18da26c Make bytecode dump work again
Dumping the bytecode before adding EOFN while depending on that to signal
the end isn't such a hot idea.
2016-05-01 00:28:37 +02:00
Günther Brammer 904bf78d68 Don't crash when deserializing an effect with object command target (#1730) 2016-04-29 00:16:20 +02:00
Günther Brammer 4092911349 Move code generation into its own class 2016-04-28 03:25:47 +02:00
Günther Brammer b00b8554ab Merge branch script 2016-04-28 03:25:44 +02:00
Günther Brammer d45ac946fe Add C4AulParseError constructor and cease reusing it for warnings
The nontrivial code that formats the position is now a function of
C4AulParse used by both warnings and errors.
2016-04-28 02:59:12 +02:00
Nicolas Hake a8f4bd3960 C4AulParseError: Avoid the second string parameter
While I'm not a big fan of hiding flow control in a function, Error()
handles formatting and saves me from calling FormatString().getData() a
lot.
2016-04-28 02:59:12 +02:00
Günther Brammer 4b43576f83 Script: Complain about some attempts to Call nonexistant function again
This code got lost in the function pointer rewrite.
2016-04-28 02:59:12 +02:00
Günther Brammer 3760363a3b Script: Add GetPrototype and SetPrototype functions
This should eventually replace the Prototype property, so that proplists
can be used as a key-value-storage without any hidden gotchas.

The Prototype is such a magical property that any code dealing with all
properties has to special-case it anyway, and isn't even returned by
GetProperties().
2016-04-28 02:59:11 +02:00
Günther Brammer 525cdc11a3 Deduplicate calculation of the relative stack position of local variables 2016-04-28 02:59:11 +02:00
Günther Brammer 071feaa78f Deduplicate loop control handling in the script parser 2016-04-28 02:59:11 +02:00
Günther Brammer efd4724084 Script: Add Scenario effects
These work just like global effects, except that effects from CreateEffect
get the scenario as target parameter in the callbacks.
2016-04-28 02:53:21 +02:00
Günther Brammer 97406d24d2 Script: Add Construction and Destruction effect callbacks 2016-04-28 01:08:04 +02:00
Günther Brammer 50378ffda0 Script: CreateEffect starts effects that receive callbacks themselves 2016-04-28 01:08:04 +02:00
Sven Eberhardt 881534bee0 Qt Editor: Shape properties 2016-04-25 16:17:10 -04:00
Lukas Werling aeabe28d82 Remove AsyncRandom() script function
We couldn't think of any reason you'd want to use this over regular
Random() in script.
2016-04-25 17:18:07 +02:00
Günther Brammer e5cfb1858f Script: GetName() can return the property a proplist was defined in
This means that the ActMaps do not need to repeat their name anymore,
provided that all Scripts use GetName() instead of directly accessing .Name.
2016-04-24 19:40:29 +02:00
Günther Brammer 5a470f51f8 Move Effect functions to C4Script.cpp 2016-04-24 19:40:29 +02:00
Günther Brammer 2cdf553953 Change effect list getting function parameter type to C4PropList*
This makes it possible to move the effect functions to C4Script.cpp.
2016-04-24 19:40:29 +02:00
Günther Brammer e8811a7b21 Move global effects from ::Game to ::ScriptEngine
This even enables some simplification in the CompileFuncs, since the global
effects were already put in the same section as the other ScriptEngine
parts. The callback for updates due to relinks also fits nicely.

The reset in C4Game::Default was redundant with C4Game::Clear already.
2016-04-24 19:40:28 +02:00
Günther Brammer e2c6c2a841 Do not use C4Object in C4Effect
Instead, the pointer to the effect list is passed to the functions that
previously used the object to determine it.
2016-04-24 19:40:28 +02:00
Günther Brammer c89e73608b Unite getting the effects list from a C4Object pointer into a function
This way, that function can be re-implemented in standalone c4script.
2016-04-24 19:40:28 +02:00
Günther Brammer 42a15e3be9 Convert C4Effect parameters that do not need to be C4Object* to C4PropList* 2016-04-24 19:40:28 +02:00
Günther Brammer bfb9b6b1fd Drop the roundtrip through C4ID for the effect C4Def command target
Unfortunately, this complicates the C4Effect::CompileFunc to stay
compatible.
2016-04-24 19:40:27 +02:00
Günther Brammer 632c5cbd0f Refactor effect callbacks into helper functions 2016-04-24 19:40:27 +02:00
Günther Brammer e22ca51f72 Don't leak references to Strings on script errors (#583) 2016-04-24 19:40:27 +02:00
Günther Brammer 5fbac346d3 Incompatible type warnings work for parameters with type declarations 2016-04-24 19:40:27 +02:00
Günther Brammer 55572720bc Make the C4ScriptHost a ComponentHost again 2016-04-24 19:40:27 +02:00
Günther Brammer fb76308812 Make C4ValueConv::Type a constexpr variable instead of an inline function 2016-04-24 19:40:26 +02:00
Nicolas Hake 19a3d43558 Fix definition of explicitly sized enums 2016-04-24 15:20:28 +02:00
Nicolas Hake baad3aef3c C4ScriptHost: add const proplist accessor
This accessor does not need to be virtual itself, because we don't want
people to override it; it calls the nonconst accessor anyway, which is
virtual.
2016-04-24 14:01:23 +02:00
Nicolas Hake 96223f154c C4ValueMapNames: mark GetItemNr const
It doesn't change anything, so callers don't need a nonconst object.
2016-04-24 14:01:23 +02:00
Nicolas Hake caf44e2473 Remove specious space from Aul operator table 2016-04-24 14:01:23 +02:00
Nicolas Hake 770be2dafe Aul: Allow AB_ERR to carry more detailed error information 2016-04-24 14:01:23 +02:00
Nicolas Hake 367f58b1cc C4AulParseError: Enable creation from host and source pointer
Instead of having a C4AulParseError constructor read the location data
from the parse state, allow explicit construction from a known location.
2016-04-24 14:01:23 +02:00
Nicolas Hake cfdb1142b8 Move C4AulParse declaration into separate header 2016-04-24 14:01:23 +02:00
Sven Eberhardt c0228be4e7 Qt Editor: More editor property types and functionality 2016-04-16 22:05:35 -04:00
Sven Eberhardt 2a2fc68e3f Qt Editor: Add user properties 2016-04-09 14:29:02 -04:00
Nicolas Hake aa06b3b6f6 C4AulParse: Drop unused ATT_STAR
ATT_STAR has been rolled into ATT_OPERATOR and is no longer used
anywhere.
2016-04-07 20:52:31 +02:00
Nicolas Hake f963a398aa Define NORETURN annotation for MSVC 2016-04-07 20:52:28 +02:00
Sven Eberhardt 879d501592 Merge remote-tracking branch 'remotes/origin/qteditor' into qteditor
Conflicts:
	src/editor/C4ConsoleQtPropListViewer.cpp
	src/editor/C4ConsoleQtPropListViewer.h
	src/script/C4ValueArray.cpp
2016-04-04 19:34:02 -04:00
Sven Eberhardt 98c36e5955 Qt Editor: Implement setting of properties 2016-04-03 23:46:58 -04:00
Sven Eberhardt e8f48fd53e Qt Editor: Win32 build fixes 2016-04-03 23:46:20 -04:00
Nicolas Hake 9dddf289db Merge branch 'master' into qteditor 2016-04-03 21:06:32 +02:00
Nicolas Hake eabca223f5 Update all copyright notices for 2016 2016-04-03 20:24:42 +02:00
Nicolas Hake 493c276126 Rewrite header inclusions to #include "path/to/file.h" style 2016-04-03 20:24:42 +02:00
Nicolas Hake 0537df5f23 C4Object: Move C4Def.h dep out of header
C4Def is only ever used as a pointer inside C4Object.h, so we don't need
to include C4Def.h from it.
2016-04-03 13:24:26 +02:00
Maikel de Vries d6b963d321 remove unused LineMaxDistance property 2016-03-22 22:26:46 +01:00
Günther Brammer b54ddc7663 Merge branch script 2016-03-01 03:04:17 +01:00
David Dormagen 4c6d347c4d C4ValueArraySortStringscomp: silenced string-to-bool-conversion warning
VisualStudio gave a "performance warning" about this implicit cast. I actually don't know why, but this change makes the intention clearer anyway (since we are not returning the string contents but just whether they exist). So it's probably not bad regardless of whether the warning is weird.

http://stackoverflow.com/questions/1847860/why-is-there-a-performance-warning-on-cast-pointer-to-bool
2016-02-27 11:42:37 +01:00
Sven Eberhardt 771a333e21 Qt Editor: Add effects to object list view + fixes
Also remove cache of C4Values and use callbacks on object and effect deletion instead.
2016-02-21 22:23:42 -05:00
Sven Eberhardt 2af22ee824 New editor (Qt-based)
Work in progress. So far only for Windows.
2016-02-15 08:38:06 -05:00
Günther Brammer 0c0c64642a Remove unused #define in C4AulParse 2016-02-12 17:15:46 +01:00
Maikel de Vries 159dbf071f make ContactCalls a property instead of DefCore entry
This allows for useful runtime changes, like disabling contact calls when an animal dies.
2016-02-08 21:25:43 +01:00
Günther Brammer fdbad8fe83 Simplify the test for loop end in parameter parsing
Instead of storing in fDone whether the token is a ')', make that the loop
condition.
2016-02-02 02:57:50 +01:00
Günther Brammer f1b99aa355 Avoid pushing and popping an unused parameter with ... 2016-02-02 02:57:49 +01:00
Günther Brammer 6a6c0d8b0b Optionally warn about too many parameters in -> calls, too
While at it, only consult the right function for direct calls, not any
other function with the same name.
2016-02-02 02:57:49 +01:00
Günther Brammer b2c263bd0e Don't mark the condition of do-while as a jump target without a continue
In contrast to the other loops, where the condition is always jumped to.
2016-02-02 02:57:49 +01:00
Günther Brammer 00f013d59e Optimize accessing the same variable as was just now set 2016-02-02 02:57:49 +01:00
Günther Brammer b7eff7f55f Set jump target flag for bytecode added after MakeSetter removed one
Also avoid removing the original bytecode if it is DUP, LOCALN or GLOBALN.
This way, setting the jump target flag can be avoided in some cases.
2016-02-02 02:57:49 +01:00
Günther Brammer 532b47ed27 Optimize do; while(!...) from two bytecodes to one
This revealed that the code for setting Par.i was wrong before, but didn't
matter because the jump target for all CONDN was set afterwards. But the
jumptarget for COND was set directly, and must be adjusted to account for
the bytecode that gets optimized away.
2016-02-02 02:57:49 +01:00
Günther Brammer 168ac8bb40 Remove pointer to start of variables from function context
It pointed always to Pars + Func->GetParCount(). The only users were
VARN_CONTEXT, which can be replaced with PARN_CONTEXT that way, and
FOREACH_NEXT, where the parser can do the math and simply give a number
relative to the current stack position, like regular variable usages do.
2016-02-02 02:57:48 +01:00
Günther Brammer 45003d55fb Guard against script stack overflow on the first script call, too
This can happen when an engine function is made to call a script function
when the stack is almost exhausted. Since there was nothing catching that
exception, it'd mean a program abort. Move the bulk of the exception
handler to the outer Exec function, and only keep the saving of the exact
code position in the inner one.

While at it, simplify the pushing of the parameters to simply push the
right amount of parameters instead of pushing ten and then popping the
excess. Also move the creation of dummy parameters for DirectExec into
DirectExec().
2016-02-02 02:57:48 +01:00
Günther Brammer 5bb3d7cb77 Use a null C4ScriptHost to parse DirectExec code
This mostly makes Parse_Expression use the case for functions in proplists
instead of the other for local variable lookup.
2016-02-02 02:57:48 +01:00
Günther Brammer ac9106d197 Remove some unused and unsound C4Value operators 2016-02-02 02:57:48 +01:00
Günther Brammer 39d04360c4 Add some const (C4StringTable::FindString) 2016-02-02 02:57:48 +01:00
Günther Brammer 87689d9f49 Move the global proplist from a member of ScriptEngine to an ancestor
While at it, denumerate the global proplist. Not that it contains anything
to denumerate, but someday it might?
2016-02-02 02:57:48 +01:00
Günther Brammer 6f98fb2e66 Remove C4AulScript class
It isn't needed to hold engine functions anymore, because those are just
put into C4PropLists.
2016-02-02 02:57:47 +01:00
Günther Brammer 9dafc6424b Make the ScriptEngine not a C4AulScript
Every script has its own C4ScriptHost, the ScriptEngine doesn't use
anything from C4AulScript.
2016-02-02 02:57:47 +01:00
Günther Brammer 473415bafa Stop using virtual functions to distinguish profiling all or some functions 2016-02-02 02:57:47 +01:00
Günther Brammer 9742a404ff Move Script Parser warning function to C4ScriptHost 2016-02-02 02:57:47 +01:00
Günther Brammer a6020197d7 Move script string table to C4ScriptHost
The string table in C4AulScriptEngine was never loaded.
2016-02-02 02:57:47 +01:00
Günther Brammer d3890f8c99 Remove empty C4AulScript::Clear()
The virtual call was only made from ~C4AulScript, and the deriving classes
already called their own Clear() from their own destructors.
2016-02-02 02:57:47 +01:00
Günther Brammer b21acff0c7 Move Scriptparser State into C4ScriptHost 2016-02-02 02:57:46 +01:00
Günther Brammer 2fe0beebdb Move contents of src/gamescript into other directories
C4Effect will get moved into the ScriptEngine, and just three source files
is a bit too little for one directory.
2016-02-02 02:57:46 +01:00
Günther Brammer 2ebd1a98ad Script: Functions in constant proplists can access their properties 2016-02-02 02:57:46 +01:00
Günther Brammer f757706e68 Make the C4Script tokenizer context-independant 2016-02-02 02:57:46 +01:00
Günther Brammer 9193c8938b Retire the split between Parse_Expression and Parse_Expression2
In earlier C4Script versions, there were multiple variants of expressions,
all followed by the same operator options, but nowadays everything is more
uniform.
2016-02-02 02:57:46 +01:00
Günther Brammer 79043c8424 Reset the size of a C4Set in Clear()
This bug manifested itself in mysteriously growing PropLists with nil keys.

Some usages of Clear were simply to clean the newly-allocated table, and
need to continue to do so.
2016-01-25 00:54:58 +01:00
Günther Brammer 88185a60f9 Script: Sort the result of GetProperties lexically
Also, deal with non-string values in the C4ValueArray properly.
2016-01-25 00:00:59 +01:00
Günther Brammer 5708ba2e72 Remove superfluous wrapper function C4AulStartTrace 2016-01-25 00:00:58 +01:00
Günther Brammer 9dadfba5af Move GlobalNamed.SetNameList call after Link() into Link()
It isn't clear whether that call is necessary since the C4AulScriptEngine
constructor already does this, but it is clear that duplicating the call
all over is a bad idea.
2016-01-25 00:00:58 +01:00
Günther Brammer 5be63d1e96 Use macros to reduce duplication in script engine definitions
While at it, make AddFunc take a C4PropList* instead of a C4AulScript*.
2016-01-25 00:00:58 +01:00
Günther Brammer 5287121d86 Use void instead of C4Void for engine functions that always return nil
This allows the removal of quite a few return C4Void();.

Also stop pretending that Nillable<void> is the same class as Nillable<T>.
Its only function was as an implementation detail for C4Void, which doesn't
need any implementation details anymore.
2016-01-25 00:00:58 +01:00
Günther Brammer f78d7712a5 Replace C4AulDefFuncHelper with template functions
This avoids duplication of code in C4AulObjectFunc and C4AulEngineFunc
at the cost of boilerplate code working around the lack of partial
function template spezializations.

Instead of ThisImpl and ExecImpl, we could have multiple C4AulEngineFunc
spezializations deriving from a common template, but that would require
even longer and duplicated boilerplate.
2016-01-25 00:00:58 +01:00
Günther Brammer 22113fd6fc Convert C4AulDefFunc* templates to variadic templates 2016-01-25 00:00:58 +01:00
Günther Brammer 0a8960f969 Reimplement C4AulParSet constructor as a variadic template
This allows the constructor to accept all types there is a C4Value
constructor for.
2016-01-25 00:00:57 +01:00
Günther Brammer 6b514893f9 Replace C4ValueConv::ToC4V with C4Value constructors
Also don't rely on int32_t != long and drop now unnecessary MSVC workaround.
2016-01-25 00:00:57 +01:00
Günther Brammer b08f51372a Add more overloads of the C4Value constructor
This allows one to use the C4Value constructor instead of
C4ValueConv. To avoid unintended implicit conversions like
const char * to bool, add a private template constructor that
catches everything not in the list of intended constructors.
2016-01-25 00:00:57 +01:00
Günther Brammer 05359179e7 Initialize C4AulParSet from C4Value[] with a function, not constructor
This avoids confusion with a variadic template constructor that could take
the same arguments.
2016-01-24 12:27:23 +01:00
Günther Brammer 234101ddbc Remove C4Script.h from C4Aul.h 2016-01-24 12:27:23 +01:00
Günther Brammer c3c402061b Move struct C4ScriptConstDef to C4AulDefFunc.h 2016-01-24 12:27:23 +01:00
Günther Brammer 20c22582ec Move DirectExec from C4AulScript to C4AulExec
In the long term, there is no reason DirectExec should be concerned with
C4AulScript/C4ScriptHost. In the meantime, the lookup code from Fneval can
be moved into the function.

This allows eval in scenario script to access scenario script locals, but
that seems harmless.
2016-01-24 12:27:23 +01:00
Günther Brammer 7cc1334963 Move C4ValueToMatrix helper functions to the file using them most 2016-01-24 12:27:23 +01:00
Günther Brammer 4f620c1537 Parse array expression with fewer lines of code
Instead of tracking the status with a variable, simply test the loop-end
condition directly, and reduce code duplication between empty and non-empty
array contents.
2016-01-24 12:27:23 +01:00
Günther Brammer b7bd48a73f Unify the various Parse_-Functions to consume the last token they match 2016-01-24 12:27:23 +01:00
Günther Brammer 6a5b571fe3 Drop warning about trailing comma at the end of a parameter list
A trailing comma does not change the behaviour of a function call, so it is
totally harmless.
2016-01-24 12:27:23 +01:00
Günther Brammer 4c01592196 Move C4AulScriptFunc into its own source file 2016-01-24 12:27:23 +01:00
Günther Brammer 514c2b8f34 Combine C4String, C4AulFunc, C4ValueArray reference counting 2016-01-24 12:27:23 +01:00
Günther Brammer ca9d95b25f Replace various C4AulFunc::Exec with C4PropList::Call
In C4Control.cpp, this improves correctness by selecting the right global
function instead of a random function.
2016-01-24 12:27:23 +01:00
Günther Brammer 93bf8f4779 Script: Allow "new Foo {}" in constant expressions 2016-01-24 12:27:23 +01:00
Günther Brammer f6c2906660 Script: Constant proplist expressions can contain function definitions
Most of the changes are for exception safety. The parser references the
function stored in Fn when the function body contains a syntax error, so
the function has to stay around. In order to avoid memory leaks, store the
function and its containing proplist in their destinations before they get
fully parsed.

This doesn't allow functions directly in static constants or arrays.
Future work: Putting the owning proplist in the scope chain.
2016-01-24 12:27:23 +01:00
Günther Brammer 507b63a55a Functions store their containing proplist instead of the C4AulScript
The C4AulScript containing the source of the function was already mostly
used to get the relevant proplist or available from context. This will
allow more than one proplist plus the global one per scripthost to contain
functions.
2016-01-24 12:27:23 +01:00
Günther Brammer 4d1f5d95c2 Script: Prevent usage of deleted objects via this()
Apparently, this wasn't done already because of compatibility concerns. The
beginning of a release cycle is the perfect moment to finally complete the
prevention of using deleted objects from script.
2016-01-24 12:25:15 +01:00
Günther Brammer 7c022085ee Improve script bytecode dump formatting slightly 2016-01-24 02:09:15 +01:00
Günther Brammer e790d2c327 Remove duplicated stubs for the scriptengine from mape 2016-01-24 02:09:14 +01:00
Günther Brammer 5a570b96f1 Remove now unnecessary stubs from C4ScriptStandaloneStubs 2016-01-24 02:09:14 +01:00
Günther Brammer 6b6dd96719 Move GameScript.GRBroadCast to Game.GRBroadCast
This avoids a dependency on ::Objects from C4ScriptHost.
2016-01-24 02:09:14 +01:00
Günther Brammer e1a38ee010 Move references to ::Objects and ::MaterialMap from C4AulLink to C4Game
This changes the order in which the various parts of the engine are updated
after a definition reload, but they should not interfere with each other.
2016-01-24 02:09:14 +01:00
Günther Brammer 9833c1ef2d Remove never used NeedDefinitionContext
Every function that accepts a definition also accepts an object instead, so
NeedNonGlobalContext is the exception to use.
2016-01-24 02:09:13 +01:00
Günther Brammer b7ecc49a02 Remove a bit of dead code from C4Value 2016-01-24 02:09:13 +01:00
Nicolas Hake 4fddda20f9 C4Script: Accept array parameter for Min, Max
Min/Max with array parameter will return the smallest/largest value of
all elements of the array. If any array element is not an integer, nor
convertible to integer, the function will fail.
2016-01-23 13:49:10 +01:00
Nicolas Hake 9a9bcd0568 C4AulError: derive from std::exception 2016-01-23 13:49:08 +01:00
Günther Brammer a5af9089a8 Script: Check parameter types of engine callbacks, too
This prevents a crash when an incompatible engine function is used as an
engine callback function.

Unfortunately, this breaks any scripts that have wrong type information in
engine callbacks and only worked because those were ignored.
2016-01-16 18:26:18 +01:00
Günther Brammer 21d8a2a64a Use 32 bit math for +1, ++, -1, etc. in script (#1389)
The engine has a few more usages of the operators, but they don't look
prone to overflowing. The other operators in Script already used SetInt,
which always truncates to 32 bit.
2016-01-15 20:19:21 +01:00
Günther Brammer 00a4c6c428 Replace BorderBound DefCore value with BorderBound object property 2016-01-01 22:18:41 +01:00
Günther Brammer 16ef28e05f Drop unused C4VERSIONBUILDNAME and C4ENGINEINFO
This was used to name snapshot releases of the Network2 branch, and has
seen almost no use since.

C4ENGINEINFO(LONG) was a duplicate of C4ENGINENAME and C4ENGINECAPTION.
2015-12-29 15:47:55 +01:00
Günther Brammer 8e889479cc Script: Find_Property can also search for engine-defined properties
Previously it used a C4PropList API that only checked the properties
set by script.
2015-12-22 18:07:38 +01:00
Nicolas Hake 1f020542d2 Implement Translate() falling back on missing translations (#1502)
Translate() used to select the script which it checked for translations
before actually looking up the string key. Change it so if the object
the context of which it was called in doesn't have a matching
translation, the string table of the script containing the call is used
instead.
2015-12-17 18:56:05 +01:00
Nicolas Hake 617a0828fb Aul: Throw exceptions by value, not by pointer
Throwing values instead of pointers simplifies memory management at the
catch site.
2015-12-08 13:17:40 +01:00
Nicolas Hake 96fcf1389a Aul: Make engine not automatically log error summary
Getting the error summary written to the log/console automatically may
be useful for general game usage, but when testing Aul we just end up
with thousands of useless messages in the output. Let the caller log the
message if it's really desired.
2015-12-08 13:17:39 +01:00
Sven Eberhardt 310daf8b3f Fix static const arrays (#906) 2015-12-07 23:38:40 -05:00
Sven Eberhardt d758c85028 Add max memory time to music resume feature (#1461) 2015-12-03 19:17:41 -05:00
Nicolas Hake 24b54211c5 Drop Min, Max, Swap for std::min, std::max, std::swap
The C++ standard library comes with perfectly fine implementations of
these functions, so there's no point in reimplementing them just for the
hell of it.
2015-11-15 13:53:01 +01:00
Sven Eberhardt d136dc22c0 Implement landscape inflammation.
It used to create the non-existent FLAM objects from the engine. Use a script callback to a global function that creates Flame objects instead.
2015-10-09 16:24:16 -04:00
Peter Wortmann f0030e33e0 Warning fixes
Actually pretty sure a few of them were bugs. Hopefully no new
ones were introduced here.
2015-10-03 15:32:39 +01:00
Sven Eberhardt 17e0e2f423 Add breaks between music. 2015-09-30 22:50:18 -04:00
Sven Eberhardt d3ee2fac57 Fix sorting of script and engine functions in dropdown menu in editor. 2015-09-26 20:10:55 -04:00
Nicolas Hake 6a11e3e811 Stop checking for rvalue ref support
We already require support for std::unique_ptr, which itself requires
support for rvalue references. As such, we know we can use rvalue
references, and thus don't have to keep carrying dead code around.
2015-09-20 13:27:14 +02:00
Sven Eberhardt b683e47499 Add LightOffset property to allow light sources to origin from locations other than the object center. 2015-09-16 21:14:08 -04:00
David Dormagen cd82b41c06 particles: added CollisionDensity to specify with which kind of material a particle will collide 2015-09-12 10:53:23 +02:00
Maikel de Vries a7480ba0ef fix crash for Translate on strings without translation
Thanks to Isilkor
2015-09-12 00:11:24 +02:00
Nicolas Hake 4ae2d9f70b C4Script: Allow executing strings from cmdline instead of only files 2015-09-04 13:40:27 +02:00
Nicolas Hake 2b876a6cb6 C4Script: Split stubs from script runner 2015-09-04 13:21:06 +02:00
Nicolas Hake 082b3e7360 C4AulParse: Properly escape strings when dumping bytecode
Instead of just writing the raw string to stderr, escape them first so
newlines and other control characters don't result in strangely
formatted output.
2015-09-04 12:57:30 +02:00
Sven Eberhardt 20d3de46cd Fix some unused variables. 2015-09-03 21:26:49 -04:00
Sven Eberhardt 84fbff95a8 Add Find_Property. 2015-09-02 23:55:45 -04:00
David Dormagen ac738735b2 Merge branch 'master' into Controls
Conflicts:
	planet/Objects.ocd/Vehicles.ocd/Airplane.ocd/Script.c
	src/game/C4Game.cpp
	src/game/C4GraphicsSystem.cpp
	src/gamescript/C4GameScript.cpp
2015-09-02 08:19:34 +02:00
Sven Eberhardt 3886f76bf3 Do not hang when a C4Value with prop list pointer is not cleared at game end.
Just cause an assertion in debug mode instead.
2015-08-29 13:22:55 -04:00
Sven Eberhardt 6ab6a1ac3c Add script interface for some EFX sound modifiers. 2015-08-27 21:44:23 -04:00
Sven Eberhardt d7a0d291e2 Fix 64 bit build. 2015-08-21 15:03:13 -04:00
Sven Eberhardt cf940d639b Fix memory leak caused by circular prop list chains.
The shapes library has such pointer chains. The leaks were getting pretty heavy because they included pointers to C4AulFuncs, which kept a lot of parts of the script engine and string tables in memory.
2015-08-20 20:19:38 -04:00
Sven Eberhardt 5ec9999d4c Fix crash on global or scenario script reload.
The string table of System.ocg scripts (except the global System.ocg) pointed to nowhere after the initial load phase, but is still required for reload. Added a ref counting option to keep these string tables alive.
2015-08-20 13:15:11 -04:00
David Dormagen 36544bd56c Merge branch 'master' into Controls
Conflicts:
	planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c
	planet/Objects.ocd/Structures.ocd/Foundry.ocd/Script.c
	planet/Objects.ocd/Vegetation.ocd/Branch.ocd/Script.c
	planet/Objects.ocd/Vegetation.ocd/Trunk.ocd/Script.c
	planet/System.ocg/FindLocation.c
2015-08-02 19:24:04 +02:00
David Dormagen d5f4805f18 fixed desync
The desync was caused by PropList->GetProperties returning the properties in an arbitrary order. They are now sorted first.
The debug logs are left in place, because I assume that I will need them again and they prove to be helpful.
2015-08-02 19:12:09 +02:00
Sven Eberhardt 0d48105b46 Added shape library.
Also fixed some coconut tree reproduction issues.
2015-07-31 00:42:01 -04:00
David Dormagen 196f528201 Merge branch 'master' into Controls
Conflicts:
	planet/Objects.ocd/HUD.ocd/FancyGridMenu.ocd/DefCore.txt
	planet/Objects.ocd/HUD.ocd/GridMenu.ocd/DefCore.txt
	planet/Objects.ocd/Helpers.ocd/Dummy.ocd/Graphics.png
	planet/Objects.ocd/Items.ocd/Tools.ocd/WindBag.ocd/Script.c
	planet/Objects.ocd/Items.ocd/Weapons.ocd/Javelin.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionMenu.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/Constructor.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/Flag.ocd/Marker.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c
	planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c
	planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c
	src/game/C4Game.cpp
	src/gamescript/C4GameScript.cpp
	src/gui/C4GameMessage.cpp
	src/landscape/C4Landscape.cpp
2015-06-03 22:32:36 +02:00
Sven Eberhardt 116a5b4ae6 Add Find_InArray (#1073). 2015-04-28 18:59:50 +02:00
Nicolas Hake be1a148915 Aul: Remove C4AulAccess enum
We're not doing access controls anyway, so tracking information about it
isn't useful.
2015-03-25 22:32:19 +01:00
Nicolas Hake 5562b09dc4 Remove a lot of disabled legacy code, round 2
Maybe at some point we'll be rid of all the commented-out code that
nobody has looked at in years.
2015-03-25 20:02:53 +01:00
David Dormagen dae7f11a70 custom GUIs: added property GraphicsName to specify graphics of Symbol (if Symbol is a definition)
f.e. {Symbol = Icon_Number, GraphicsName = "Inf"}
2015-03-23 15:34:09 +01:00
Nicolas Hake e21a5bdd44 Rename BoundBy to Clamp
"BoundBy" sounds like a predicate. "Clamp" is a common function name for
the operation in graphics processing, so it should be familiar to users.
2015-02-12 23:05:55 +01:00
Nicolas Hake e2a8f6d303 Reorder some declarations and initializations to avoid order mismatch
While none of the mismatches were having a side-effect, this silences a
number of -Wreorder warnings which were drowning out potentially
important diagnostics.
2015-02-04 22:12:42 +01:00
Günther Brammer 5bcedb5bbf Remove some redundant #includes 2015-01-25 18:53:48 +01:00
Günther Brammer a92c22a7b3 Merge various build system fixes and cleanups 2015-01-25 18:50:29 +01:00
David Dormagen bd04722553 Merge branch 'master' into Controls
Conflicts:
	planet/Objects.ocd/HUD.ocd/Controller.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionMenu.ocd/Script.c
	planet/Objects.ocd/Libraries.ocd/Constructor.ocd/Script.c
	src/game/C4GraphicsSystem.cpp
	src/game/C4GraphicsSystem.h
	src/game/C4Viewport.cpp
	src/gui/C4GameMessage.cpp
2015-01-15 19:57:01 +01:00
Maikel de Vries 4ea0cb0ca6 make ContainBlast a property instead of DefCore entry 2015-01-15 17:46:53 +01:00
Julius Michaelis 8e7001ba0f Fix self-overwrite in C4ValueArray::SetSlice (#1212: Array manipulation goes wrong ) 2015-01-09 15:09:36 +09:00
Sven Eberhardt 42b9ca4577 Add custom EditCursorCommands available in editor context menu.
Example: this.EditCursorCommands = ["Explode(20)"] on an item will offer a menu entry to explode the object. Commands may be either strings or function pointers, but function pointers will always be called by name.
2015-01-03 23:21:36 +01:00