The aGorm can't code well Thread - Page 1

The aGorm can't code well Thread

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderators: Moderators, Moderators

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: The aGorm can't code well Thread

Post by knorke »

StartMoving / StopMoving get called all the time in strange situations. ie if a unit is driving and decreases speed just a tiny speed to make a turn, they get called too. (imo a bug but oh well)

To decide if threadnumber A is killed by signalnumber B some bitwise operation is used. (see Flozis link)
http://pastebin.com/raw.php?i=qEPRtcD9
X means thread gets killed.
Notice most numbers kill multiple threads at once.
Now look at row 1,2,8,16: Notice there is only one X
Some numbers only kill one thread, usually those are the ones you want to use. (ie do not want to stop the recoil animation if the unit stops walking)
1,2,8,16,32,128,256,...
:arrow: x^2

(disclaimer: not sure if 100% correct)
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

OK, so i found the bug.

Code: Select all

local function walk()
  [color=#BF0000]Sleep (math.random(100))[/color]
   Signal(SIG_WALK)
   SetSignalMask(SIG_WALK)
   while (true) do
For some reason this sleep causes it to trigger? I don't know why though. I was using it to desynce the walk cycles so large groups would look odd, (by giving them a small random delay), but I suppose I shall have to come at it another way... anyone got any good ideas how to achive somthign similar? And anyone have an explanation for why that would have been the cause?

PS thanks knorke for the paste bin, I'll start to use that from now on.

aGorm
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: The aGorm can't code well Thread

Post by knorke »

try like:

Code: Select all

local function walk()
Signal(SIG_WALK)
SetSignalMask(SIG_WALK)
Sleep (math.random(100))
   while (true) do
(set signal first, then sleep)
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

Yep... more questions for you coding gurus out there...

I have a function and I want it to call another function.

Example:

Code: Select all

function script.AimWeapon1( heading, pitch )
	--make sure the aiming animation is only run once
	Signal(SIG_AIM)
	Signal(SIG_SWING)
	SetSignalMask(SIG_AIM)
	if heading < math.rad(180) then
    AimWeapon1Left( 2, 4 )
		return true
	else
    AimWeapon1Right( 2, 4 )
		return true
	end

end

local function AimWeapon1Left( headingmod, pitchmod )
    --Spring.Echo ("left" + headingmod + pitchmod)
    Turn(body, 2, heading, math.rad(150))
		--------------------- wait
		WaitForTurn (body, y_axis)
		return true
end

local function AimWeapon1Right( headingmod, pitchmod )
    --Spring.Echo ("right" + headingmod + pitchmod)
    Turn(body, 2, heading, math.rad(150))
		--------------------- wait
		WaitForTurn (body, y_axis)
		return true
end
Now, I know at the moment the putting the aim code in there own functions is unessesery, as I could just put it stright in, but thats cause this is a realy simplfied version of what I want to do. What I'm wondering is, why would that not work?

aGorm
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6112
Joined: 29 Apr 2005, 01:14

Re: The aGorm can't code well Thread

Post by FLOZi »

iirc WaitForX and Sleep can only be called in 'threads', i.e. functions called using StartThread. This of course results in other possible problems.
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

... hmmm, OK, is there some way I can include the code (IE, like in PHP you might do an include of say your page headers, so there all referencing one file? Although in this case I just want to reference a block of code elsewere in the script...)

aGorm
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10250
Joined: 24 Jan 2006, 21:12

Re: The aGorm can't code well Thread

Post by PicassoCT »

aGorm wrote:Anyone got any good ideas how to achive somthign similar? And anyone have an explanation for why that would have been the cause?

PS thanks knorke for the paste bin, I'll start to use that from now on.

aGorm
Dont know if i can give any good avice here - but my attempt to solve this would be to have three diffrent walk animations, and to hand to every unit a diffrent walkanimation seed.

Seeds would be generated and stored while manufacturing.
Unit with seed: 332211>>doALoop would walk diffrent (just by the looks of course) then unit with 313131.

Dont know if this is a good solution though. If every unit has such a value that is constantly called during movement, the price for moving large groups could get very high, very fast.. so i would make a safetyline that doesent use the seed when more then fifty units are selected.

TL, dr; Grab yourself Code Blocks and a Compiler, and start forking things up
0 x

User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: The aGorm can't code well Thread

Post by aegis »

aGorm wrote:I have a function and I want it to call another function.
are you getting a specific error? have you tried using a forward declaration?

Code: Select all

-- forward declaration
local AimWeapon1Left, AimWeapon1Right

function script.AimWeapon1( heading, pitch )
   --make sure the aiming animation is only run once
   Signal(SIG_AIM)
   Signal(SIG_SWING)
   SetSignalMask(SIG_AIM)
   if heading < math.rad(180) then
    AimWeapon1Left( 2, 4 )
      return true
   else
    AimWeapon1Right( 2, 4 )
      return true
   end

end

local function AimWeapon1Left( headingmod, pitchmod )
    --Spring.Echo ("left" + headingmod + pitchmod)
    Turn(body, 2, heading, math.rad(150))
      --------------------- wait
      WaitForTurn (body, y_axis)
      return true
end

local function AimWeapon1Right( headingmod, pitchmod )
    --Spring.Echo ("right" + headingmod + pitchmod)
    Turn(body, 2, heading, math.rad(150))
      --------------------- wait
      WaitForTurn (body, y_axis)
      return true
end
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6112
Joined: 29 Apr 2005, 01:14

Re: The aGorm can't code well Thread

Post by FLOZi »

Derp, I didn't even think of the obvious issue. I'm so off the ball lately. :?
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

OK, so I worked a way around my problem... (by not trying to do it that way, I realised I was being stupid and trying to do somthing I didn't even need)

I'm wondering though... is there a limit on the number of threads in a script? Currently I have 4, will going to 5 make it slow down loads if there are many units? How about 6 or 7? Has anyone tested this?

aGorm
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: The aGorm can't code well Thread

Post by knorke »

I guess eventually too much of anything is bad. But in practice it does not seem to matter much/at all.
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

Code: Select all

local function RestoreAfterDelay()
  Signal(SIG_RESTORE)
	SetSignalMask(SIG_RESTORE)
	while (true) do
	Sleep(RESTORE_DELAY)
	aiming = 0
	Turn(body, 2, 0 ,math.rad(500))
	Turn(head, 2, 0, math.rad(150))
	Turn(head, 1, 0, math.rad(150))
	Turn(R_upper, 3, 0, math.rad(200))
	Turn(R_upper, 2, 0, math.rad(200))
	Turn(R_upper, 1, 0, math.rad(200))
	Turn(L_upper, 3, 0, math.rad(200))
	Turn(L_upper, 1, 0, math.rad(200))
	Turn(L_lower, 1, 0, math.rad(200))
	Turn(L_lower, 2, 0, math.rad(200))
        Turn(R_upper, 3, 0, math.rad(400))
        Turn(R_lower, 2, 0, math.rad(200))
        Turn(R_hand, 2, 0, math.rad(200))
        Turn(R_lower, 3, 0, math.rad(150))
        Spring.Echo ("im restoring")
        Signal(SIG_RESTORE)
  end
end
Any idea how you stop a thred from with itself? Apparenly signaling it from within itself doesn't work.
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6112
Joined: 29 Apr 2005, 01:14

Re: The aGorm can't code well Thread

Post by FLOZi »

It's a function, you can just use a return statement to leave it
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

Code: Select all

[f=0000078] WARNING: could not load model "objects3d/cybernaut_h.s3o" (missing file?)
[f=0000078] Spring 0.82.7.1 (0.82.7.1) has crashed.
[f=0000078] Exception: Access violation (0xc0000005)
[f=0000078] Exception Address: 0x007c15a1
:( I broke it... for some reason it thinks the files not there even though it is. So I'm assumeing that I've prob missed something. I've re exported the s30 incase it was corrupt, check all the piece names are correct, set a height and hitbox... is there somthing else that could result in this error?

aGorm
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6112
Joined: 29 Apr 2005, 01:14

Re: The aGorm can't code well Thread

Post by FLOZi »

Did you reset the textures when re-exporting / resaving the s3o?
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

I was an idiot.... had changed the textures to dds, and forgot to go back though my s3o's and re name....

Now I have a very odd problem. I have to units, both using pretty much the same script. Both have a walk cycle that is identical (sharing teh same legs as they do). But for some reason I can't quite figure out, the walk on one is messed up and on the other isn't. I've been pulling my hair out and final have narrowed it down to this:

Code: Select all

function script.StartMoving()
 Spring.Echo ("starting to walk!")
 StartThread (walk)
 Signal(SIG_REST)
end

function script.StopMoving()
 Spring.Echo ("stopped walking!")
 StartThread (rest)
 Signal(SIG_WALK)
 StartThread(legs_down)
end
For some reason "function script.StopMoving()" keeps being called on one unit. its walking just teh same as the other one, but were as one just pings "starting to walk!" at teh start and "stopped walking!" when it reaches its destination, the second unit keeps pinging both all the time its walking (hence the walk cycle is stoped and started from the start again all the time.)

Has anyone else had a smililar issue at all? I can't help think its not so much the script but maybe somthing in the unit defs? Can you have a max-speed less than 1? Thats the only difference I think?

aGorm
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10250
Joined: 24 Jan 2006, 21:12

Re: The aGorm can't code well Thread

Post by PicassoCT »

yes, i had similar issues. You actually can see it in the console, the unit is stoping all the time. While Turning. While coming to a hill.. encountering friends and so on.

Trick is to make the stop thread slightly timedelayed, so when the unit starts walking again, the signal kills the stopthread before it can signal the walkthread to be killed.
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6112
Joined: 29 Apr 2005, 01:14

Re: The aGorm can't code well Thread

Post by FLOZi »

Speed is a float so that should be fine. Picasso is probably on the right track
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10250
Joined: 24 Jan 2006, 21:12

Re: The aGorm can't code well Thread

Post by PicassoCT »

FLOZi wrote:Speed is a float so that should be fine. Picasso is probably on the right track
Is there higher praise? Im dancing in my room right noaw... :D :mrgreen:
0 x

User avatar
aGorm
Posts: 2928
Joined: 12 Jan 2005, 10:25

Re: The aGorm can't code well Thread

Post by aGorm »

OK, just did a test, if the speed is above 1, it works fine, if the speed is less, it stops and starts. It's not going over hills or anything, it's flat ground. Can someone with some knowledge of how the engine works weigh in with a reason why it would do something so stupid? I mean, I dont compleatly mind doing the sort of hack Picassos on about, it's just would it would be better if I didn't have to.

aGorm
0 x

Post Reply

Return to “Game Development”