2019-12-06 11:35 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000700Spring engineGeneralpublic2007-12-09 21:28
ReporterKDR_11k 
Assigned ToKDR_11k 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000700: [patch] more CEG opcodes
DescriptionThis patch adds some new opcodes. It also introduces buffers that are used by most of these new codes. Buffers are basically 16 (I figure that's enough) float variables that can store data for later to allow the second operand of an opcode to be determined dynamically (before it had to be a constant). Buffer indices are 0-15. Buffer contents are not initialized so reading from a buffer without writing will yield unpredictable results (this might be what enables carrying a buffer value from one part of a vector to another though, in that case please keep it that weay).

New ops:
y# - Yank: Stores the running value in the buffer # and returns 0. The name comes from Vi's copy and paste operation.
x# - Multiply: Multiplies the value with the contents of buffer #.
a# - Add: Adds the contents of buffer #.
p# - Pow: Returns the #th power of the value.
q# - Buffer Pow: Like Pow but uses the contents of buffer # as the exponent.
Additional InformationExample of use:
pos=1 i.02 y1 d8 q1 y0 i.1 s1 x0,0,1.5808 i.1 s1 x0;

This describes (if used with a high count) a spiral with the minimum radius of 8*damage. Without these new codes only a ring with a fixed radius could be described.
Written out it's

x:
Value = 1
Add index * .02
Store in buffer 1, zero value
Add damage * 8
Value ^ buffer 1
Store in buffer 0, zero value
Add index * .1
Sine of amplitude 1, phase value
Multiply with buffer 0

y:
0

z:
Value = 1.5808 (pi/2)
Add index * .1
Multiply with buffer 0
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon moarOpcodes.patch (3,070 bytes) 2007-12-04 21:26 -
    Index: Sim/Projectiles/ExplosionGenerator.cpp
    ===================================================================
    --- Sim/Projectiles/ExplosionGenerator.cpp	(revision 4926)
    +++ Sim/Projectiles/ExplosionGenerator.cpp	(working copy)
    @@ -328,11 +328,17 @@
     #define OP_SAWTOOTH	11 // Performs a modulo to create a sawtooth wave
     #define OP_DISCRETE	12 // Floors the value to a multiple of its parameter
     #define OP_SINE		13 // Uses val as the phase of a sine wave
    +#define OP_YANK     14 // Moves the input value into a buffer, returns zero
    +#define OP_MULTIPLY 15 // Multiplies with buffer value
    +#define OP_ADDBUFF  16 // Adds buffer value
    +#define OP_POW      17 // Power with code as exponent
    +#define OP_POWBUFF  18 // Power with buffer as exponent
     
     void CCustomExplosionGenerator::ExecuteExplosionCode(const char *code, float damage, char *instance, int spawnIndex, const float3 &dir)
     {
     	float val = 0.0f;
     	void* ptr = NULL;
    +	float buffer[16];
     
     	for (;;) {
     		switch (*(code++)) {
    @@ -414,6 +420,32 @@
     				code += 4;
     				break;
     			}
    +			case OP_YANK: {
    +				buffer[(*(int*) code)] = val;
    +				val = 0;
    +				code += 4;
    +				break;
    +			}
    +			case OP_MULTIPLY: {
    +				val *= buffer[(*(int*) code)];
    +				code += 4;
    +				break;
    +			}
    +			case OP_ADDBUFF: {
    +				val += buffer[(*(int*) code)];
    +				code += 4;
    +				break;
    +			}
    +			case OP_POW: {
    +				val = pow(val, (*(float*) code));
    +				code += 4;
    +				break;
    +			}
    +			case OP_POWBUFF: {
    +				val = pow(val, buffer[(*(int*) code)]);
    +				code += 4;
    +				break;
    +			}
     			default: {
     				assert(false);
     				break;
    @@ -452,20 +484,36 @@
     			char c;
     			do { c = script[p++]; } while(c == ' ');
     
    +			bool useInt=false;
    +
     			if (c == 'i')      opcode = OP_INDEX;
     			else if (c == 'r') opcode = OP_RAND;
     			else if (c == 'd') opcode = OP_DAMAGE;
     			else if (c == 'm') opcode = OP_SAWTOOTH;
     			else if (c == 'k') opcode = OP_DISCRETE;
     			else if (c == 's') opcode = OP_SINE;
    +			else if (c == 'y') {opcode = OP_YANK; useInt=true;}
    +			else if (c == 'x') {opcode = OP_MULTIPLY; useInt=true;}
    +			else if (c == 'a') {opcode = OP_ADDBUFF; useInt=true;}
    +			else if (c == 'p') opcode = OP_POW;
    +			else if (c == 'q') {opcode = OP_POWBUFF; useInt=true;}
     			else if (isdigit(c) || c == '.' || c == '-') { opcode = OP_ADD; p--; }
     			else throw content_error("Explosion script error: \"" + script + "\"  : \'" + string(1, c) + "\' is unknown opcode.");
     
     			char* endp;
    -			float v = (float)strtod(&script[p], &endp);
    -			p += endp - &script[p];
    -			code += opcode;
    -			code.append((char*) &v, ((char*) &v) + 4);
    +			if(!useInt) {
    +				float v = (float)strtod(&script[p], &endp);
    +				p += endp - &script[p];
    +				code += opcode;
    +				code.append((char*) &v, ((char*) &v) + 4);
    +			}
    +			else {
    +				int v = (int)strtol(&script[p], &endp, 10);
    +				if (v < 0 || v > 16) throw content_error("Explosion script error: \"" + script + "\"  : Buffer index is out of bounds.");
    +				p += endp - &script[p];
    +				code += opcode;
    +				code.append((char*) &v, ((char*) &v) + 4);
    +			}
     		}
     
     		switch (bt->id) {
    
    patch file icon moarOpcodes.patch (3,070 bytes) 2007-12-04 21:26 +

-Relationships
+Relationships

-Notes

~0001481

KDR_11k (reporter)

Ooops, forgot to mention the Sine for z in the example write-out...

~0001484

KDR_11k (reporter)

Committed in r4969 with my new SVN privileges. Yay!
+Notes

-Issue History
Date Modified Username Field Change
2007-12-04 21:26 KDR_11k New Issue
2007-12-04 21:26 KDR_11k File Added: moarOpcodes.patch
2007-12-04 21:29 KDR_11k Note Added: 0001481
2007-12-09 21:27 KDR_11k Status new => assigned
2007-12-09 21:27 KDR_11k Assigned To => KDR_11k
2007-12-09 21:28 KDR_11k Note Added: 0001484
2007-12-09 21:28 KDR_11k Status assigned => resolved
2007-12-09 21:28 KDR_11k Resolution open => fixed
+Issue History