| 03-21-2010, 06:46 PM | #1 |
Ok, so I've been exploring the xe engine code, and I've been gladly capable of learning a few things. And one thing I've learned was how to use delegates. or I thought. Well I'm delegating a struct inside another one, pretty much like xefx is delegated inside xecollider. But when I test my system, the missiles don't move, the effects aren't created, it seems that the dummies aren't being created but they are actually. However if I put debug messages on every method that is called, all messages will appear in-game but no change at all. I'll post here the code, I'm afraid it's in Zinc, but any vJasser can read it, if I can read both vJass and Zinc, who can't? Main://! zinc library DyMotionMain { constant integer FPS = 30; public constant integer dm_DUMMY_ID = 'h000'; public constant real dm_UPDATE_INTERVAL = 1.0 / FPS; } //! endzinc Projectile://! zinc library DyMotionProjectile { public struct dmProjectile { private unit object; private effect fx = null; static method create( real x, real y ) -> dmProjectile { dmProjectile msl = dmProjectile.allocate( ); msl.object = CreateUnit( Player(0), dm_DUMMY_ID, x, y, 0.0 ); return msl; } method operator FXPath= ( string value ) { if ( fx != null ) DestroyEffect( fx ); if ( value == "" ) fx = null; else fx = AddSpecialEffectTarget( value, object, "origin" ); } method operator X ( ) -> real { return GetUnitX( object ); } method operator X= ( real value ) { SetUnitX( object, value ); } method operator Y ( ) -> real { return GetUnitY( object ); } method operator Y= ( real value ) { SetUnitY( object, value ); } } } //! endzinc Motion://! zinc library DyMotionMotion requires DyMotionMain, DyMotionProjectile { public struct dmMotion { private delegate dmProjectile msl; private real spd = 0.0; private real acc = 0.0; private real ang = 0.0; private real angspd = 0.0; method operator Speed ( ) -> real { return spd; } method operator Speed= ( real value ) { spd = value; } static method create( real x, real y, real speed, real angle ) -> dmMotion { dmMotion m = dmMotion.allocate( ); m.msl.create( x, y ); m.ang = angle; m.Speed = speed; if ( dmMotion.N == 0 ) TimerStart( dmMotion.T, dm_UPDATE_INTERVAL, true, dmMotion.update ); m.id = dmMotion.N; dmMotion.M[dmMotion.N] = m; dmMotion.N += 1; return m; } private integer id; private static timer T; private static integer N = 0; private static dmMotion M[]; private static code update; private static method Update( ) { dmMotion m; integer i; for( 0 <= i < dmMotion.N ) { m = dmMotion.M[i]; m.X = m.X + m.Speed * Cos( m.ang ); m.Y = m.Y + m.Speed * Sin( m.ang ); } } method onDestroy( ) { dmMotion.N -= 1; dmMotion.M[id] = dmMotion.M[dmMotion.N]; dmMotion.M[id].id = id; if ( dmMotion.N == 0 ) PauseTimer( dmMotion.T ); } private static method onInit( ) { dmMotion.update = function dmMotion.Update; dmMotion.T = CreateTimer( ); } } } //! endzinc TestCode://! zinc library main requires SimpleMovingEngine { function onInit( ) { real x = GetStartLocationX( GetPlayerStartLocation( Player(0) ) ); real y = GetStartLocationY( GetPlayerStartLocation( Player(0) ) ); dmMotion m; MeleeClearExcessUnits( ); CreateFogModifierRectBJ( true, Player(0), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea ); udg_Hero = CreateUnit( Player(0), 'Hblm', x, y, GetRandomReal( 1, 359 ) ); SelectUnit( udg_Hero, true ); m = dmMotion.create( x, y, 15.0, 0.0 ); m.FXPath = "Abilities\\Weapons\\FrostWyrmMissile\\FrostWyrmMissile.mdl"; } } //! endzinc you can notice that creating a new projectile in my system (attempt) is pretty much the same way as creating one in xe. Damn it! the code appears all red here lol, no way to fix it though. |
| 03-22-2010, 12:43 AM | #2 | |
Quote:
Anyway, try changing the line m.msl.create( x, y ); into m.msl=dmProjectile.create(x, y); |
| 03-22-2010, 11:18 AM | #3 |
god I can't believe I lost 2 days because of such a tiny problem. Thanks a lot, where was my head anyway? |
