Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
* changed exec command to have a "ignoremissing" argument after the …
Browse files Browse the repository at this point in the history
…script name (broken)

 * renamed /scripts to /spawn
 * removed spawn* commands from gravit.cfg
 * changed recordingvideorefreshtime to 100



git-svn-id: svn://gakman.com/gravit/trunk@258 60970b36-f649-e149-802f-859a9d0a703e
  • Loading branch information
gak committed May 28, 2005
1 parent 9eb7420 commit addf0ec
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 74 deletions.
10 changes: 6 additions & 4 deletions command.c
Expand Up @@ -397,7 +397,7 @@ void cmdSpawn(char *arg) {
lua_pushnumber(state.lua, state.particleCount);
lua_setglobal(state.lua, "spawnparticles");

scriptFile = va("scripts/%s.lua", scriptName);
scriptFile = va("spawn/%s.gravitspawn", scriptName);

luaExecute(scriptFile);
lua_getglobal(state.lua, "spawn");
Expand Down Expand Up @@ -806,10 +806,12 @@ void cmdFontFile(char *arg) {
void cmdRunScript(char *arg) {

char *sz;
char *opt;
sz = strtok(arg, " ");
if (!sz)
return;
configRead(sz);
if (!sz) return;
opt = strtok(NULL, " ");
configRead(sz, (opt && !strcmp(opt, "ignoremissing")));
printf("TODO\n");

}

Expand Down
3 changes: 2 additions & 1 deletion config.c
Expand Up @@ -21,14 +21,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#include "gravit.h"

int configRead(char *filename) {
int configRead(char *filename, int ignoreMissing) {

FILE *fp;
char buffer[FILE_CHUNK_SIZE_SMALL];

fp = fopen(filename, "rb");
if (!fp) {

if (ignoreMissing) return 1;
conAdd(LERR, "Could not open script: %s", filename);
return 0;

Expand Down
25 changes: 3 additions & 22 deletions gravit.cfg
Expand Up @@ -47,7 +47,7 @@ videoantialiasing 1
# The value is how often you want your video to update in milliseconds.
# Setting this value too low will lower the performance of your recording
# Increasing it will improve rendering and spawning times
recordingvideorefreshtime 50
recordingvideorefreshtime 100

# Font Settings (doesn't work while Gravit is running)
# Feel free to use any font you want!
Expand Down Expand Up @@ -88,29 +88,10 @@ colourschemeadd 1.0 1.0 1.0 1.0
# Number of particles to spawn
# particlecount 1000
#
# Number of galaxies to spawn
# spawngalcountmin 2
# spawngalcountmax 10
#
# Possible mass for each particle, each galaxy will pick a range from these values
# spawngalmassmin 0
# spawngalmassmax 500
#
# Possible Range of galaxy radius
# spawngalsizemin 0
# spawngalsizemax 500
#
# Minimum and maximum initial velocity for a galaxy
# spawngalvelmin 0
# spawngalvelmax 50
#
# Possible area where galaxies can spawn
# spawnrangemin 0
# spawnrangemax 10000

# Example
# Uncomment the following line to make Gravit start recording automatically with nice looking settings
# exec demo.cfg

# Custom Script
exec custom.cfg
exec custom.cfg ignoremissin

2 changes: 1 addition & 1 deletion gravit.h
Expand Up @@ -627,7 +627,7 @@ extern float fpsCurrentAverageFT;
void fpsInit();
void fpsUpdate(float);

int configRead(char *filename);
int configRead(char *filename, int ignoreMissing);

void drawCube();

Expand Down
46 changes: 0 additions & 46 deletions main.c
Expand Up @@ -392,42 +392,6 @@ int commandLineRead(int argc, char *argv[]) {

#define CheckCommand(x) !strncmp(argv[i], x, strlen(x))

/*
GetValue() is good for:
--exec value
--exec=value
*/

#define GetValue() \
if (strlen(parm) == strlen(argv[i])) \
argvptr = argv[++i]; \
else \
argvptr = argv[i] + strlen(parm); \
while (argvptr[0] == ' ' || argvptr[0] == '=' || argvptr[0] == 0) argvptr++;

/*
example of checkCommandAndGetValue(x)
CheckCommandAndGetValue("--execute")
cmdExecute(argvptr);
}
because it's like this when it expands:
parm = "--execute";
if (CheckCommand(parm)) {
GetValue();
cmdExecute(argvptr);
}
*/

#define CheckCommandAndGetValue(x) parm = x; if (CheckCommand(parm)) { GetValue();

for (i = 1; i < argc; i++) {

// version, quit
Expand All @@ -446,16 +410,6 @@ int commandLineRead(int argc, char *argv[]) {

}

// -e or --exec
// runs a command
if (CheckCommand("--exec") || CheckCommand("-e")) {
conAdd(LLOW, "Sorry, --exec has been removed -- just add your commands to the command line as they are");
conAdd(LLOW, " eg. gravit exec \"\" ");
cmdQuit(0);
return 0;
continue;
}

// -n or --noscript
if (CheckCommand("--noscript") || CheckCommand("-n")) {
state.dontExecuteDefaultScript = 1;
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions spawn/binary-galaxy.lua
@@ -0,0 +1,18 @@

require("scripts/functions.lua")

function spawn()

dist = randomfloat(1,3) * spawnparticles
vel = randomfloat(20,50)
mass1min = randomfloat(500,1000)
mass1max = randomfloat(500,1000)
mass2min = randomfloat(500,1000)
mass2max = randomfloat(500,1000)
ballsize1 = randomfloat(500,1000)
ballsize2 = randomfloat(500,1000)

makeball(v(0,dist,0), v(-vel,0,0), ballsize1, 0, spawnparticles/2, mass1min, mass1max)
makeball(v(0,-dist,0), v(vel,0,0), ballsize2, spawnparticles/2, spawnparticles/2, mass2min, mass2max)

end
File renamed without changes.
8 changes: 8 additions & 0 deletions spawn/default.lua
@@ -0,0 +1,8 @@

scripts = { "one-galaxy", "binary-galaxy", "many-galaxy", "snake", "loops" }
n = table.getn(scripts)
r = math.random(1,n)
log("Spawining " .. scripts[r])
spawn = nil
require ("scripts/" .. scripts[r] .. ".lua")

File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions spawn/loops.lua
@@ -0,0 +1,61 @@

require("scripts/functions.lua")

function spawn()

curveness1 = randomfloat(0, 0.1)
curveness2 = randomfloat(0, 0.1)

curvechangelimit = 0.0001

if (randomint(0,4) == 0) then
curvechange1 = randomfloat(-curvechangelimit,curvechangelimit)
else
curvechange1 = 0
end

if (randomint(0,4) == 0) then
curvechange2 = randomfloat(-curvechangelimit,curvechangelimit)
else
curvechange2 = 0
end

speed = randomfloat(0,5)
if (randomint(0,1) == 0) then
massincrement = randomfloat(-0.01,0.01)
else
massincrement = 0
end

massrandom = randomfloat(0,100)
distance = randomfloat(0.1, 5)

pos = v(0,0,0)
vel = v(0,0,0)
ang1 = 0
ang2 = 0

for i=0,spawnparticles-1 do

pos.x = pos.x + math.cos(ang1) * distance
pos.y = pos.y + math.sin(ang1) * distance
pos.y = pos.y + math.cos(ang2) * distance
pos.z = pos.z + math.sin(ang2) * distance

vel.x = math.cos(ang1) * speed
vel.y = math.sin(ang1) * speed
vel.y = math.cos(ang2) * speed
vel.z = math.sin(ang2) * speed

ang1 = ang1 + curveness1
ang2 = ang2 + curveness2

curveness1 = curveness1 + curvechange1
curveness2 = curveness2 + curvechange2

particle(i, pos, vel, randomfloat(0,massrandom) + massincrement * i)

end

end

File renamed without changes.
11 changes: 11 additions & 0 deletions spawn/many-galaxy.lua
@@ -0,0 +1,11 @@
require("scripts/functions.lua")

function spawn()
-- work out a number of galaxies based on spawnparticles
galaxysize = randomint(10,1000)
galaxies = math.floor(spawnparticles / galaxysize) + 1
for i=0,galaxies-1 do
makeball(randomrange(galaxies * 2000), randomrange(50), randomfloat(1, 1000), spawnparticles/galaxies*i, spawnparticles/(galaxies), randomfloat(0,1000), randomfloat(0,1000))
end
end

File renamed without changes.
20 changes: 20 additions & 0 deletions spawn/one-galaxy.lua
@@ -0,0 +1,20 @@
require("scripts/functions.lua")

function spawn()
particlemassmin = randomfloat(1,1000)
particlemassmax = randomfloat(1,1000)
estmass = (particlemassmin + particlemassmax) / 2 * spawnparticles
galaxyradius = randomfloat(10,1000)
speedbase = randomfloat(0,.0001)
speedbase = .0000001
for i=0,spawnparticles-1 do
radius = randomfloat(0,galaxyradius)
speed = speedbase * radius * math.sqrt(estmass)
angle = randomfloat(0,2*math.pi)
pos = v(math.cos(angle)*radius, math.sin(angle)*radius, randomfloat(-1,1))
vel = v(math.cos(angle+math.pi/2)*speed*radius, math.sin(angle+math.pi/2)*speed*radius, 0)
mass = randomfloat(particlemassmin,particlemassmax)
particle(i, pos, vel, mass)
end
end

File renamed without changes.
41 changes: 41 additions & 0 deletions spawn/snake.lua
@@ -0,0 +1,41 @@

require("scripts/functions.lua")

function spawn()

curveness = randomfloat(0, 0.5)
speed = randomfloat(0,1)
if (randomint(0,1) == 0) then
massincrement = randomfloat(-0.01,0.01)
else
massincrement = 0
end

massrandom = randomfloat(0,100)

pos = v(0,0,0)
vel = v(0,0,0)
ang1 = 0
ang2 = 0

for i=0,spawnparticles-1 do

pos.x = pos.x + math.cos(ang1)
pos.y = pos.y + math.sin(ang1)
pos.y = pos.y + math.cos(ang2)
pos.z = pos.z + math.sin(ang2)

vel.x = math.cos(ang1) * speed
vel.y = math.sin(ang1) * speed
vel.y = math.cos(ang2) * speed
vel.z = math.sin(ang2) * speed

ang1 = ang1 + randomfloat(-curveness,curveness)
ang2 = ang2 + randomfloat(-curveness,curveness)

particle(i, pos, vel, randomfloat(0,massrandom) + massincrement * i)

end

end

0 comments on commit addf0ec

Please sign in to comment.