Skip to main content
gamedev.net
🔒 Locked

Particle Scripting

Started by tj963 2 replies 700+ views
Original Post
tj963
tj963
Hey, What''s the fastest way to run scripts for a particle system? Right now, I load the script from a text file and compile it into an array of ints. Then to run it I take the first number in the array and use it as an index into an array of function pointers. Whatever function is called reads however much data it needs of of the script, does it''s stuff, and then advaces the position in the script to the end of it''s data, which is the next command. Is this a fast way to do this or is there a better way? tj963
tj963
thona
thona
FIRST thing I would change is geting rid of the ints. Put the function pointers directly into the table :-)

And then you already talk of JIT''s - time to get this into .NET :-)


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)
GekkoCube
GekkoCube
Im curiously at how scripts are written, read, and processed.
if i used c++ for a personal scripting engine, what would be the logical answeres to the following:

what script syntax is good?
do i read it from a textfile in run-time?
how do you compile textfiles into game code?
is there an example or sample of a scripting engine..i''d rather see the syntax and maybe some source code.

thanks a bunch.
tj963
tj963
Hey,
My game is programmed in C++. My syntax is really simple, similar in style to assembly. A few lines look like:

loc 0
add 0 1 0
adddelta
jumpe 0 1 0

The first line specifies a point to jump to, the second adds variable 0 to variable 1 and stores it in variable 0, the third adds the delta(velocity) of the current particle times the time elapsed in the frame to it''s position, the third jumps to location 0 if variable 0 equals variable 1. When it''s loaded, each command is converted to an integer and the entire script is stored in an array of ints, with each an int represent a command, and then whatever data it needs following it, in the case of "add 0 1 0" 10,0,1,0 would be put in the array. The code is never compiled into game code. When I want to execute the script, I start at position zero and use whatever value is in the array there as the index into an array of function pointers, for example:

mScriptFunctions[mScript[CurrentPosition]](mScript, CurrentPos);

Then I pass the script and the current position to the function. It uses however much data it needs and advances the current position accordingly, which ends up at the next command. Just repeat until there are no more commands. If you want my messy and mostly uncommented source code, e-mail me at tjennison@hotmail.com.

tj963
tj963

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.