Exemplo n.º 1
0
/**
* cast_spell(void)
*
* @brief
* @param void
* @return void
*/
void cast_spell(void)
{
	buffer_t buffer;

	//Check for subscript out of range
	if(!tempdata()->spell_selected || tempdata()->spell_selected >= MAX_PLAYER_SPELLS)
		return;

	//Check if player has enough MP
	if(player(myindex())->spells[tempdata()->spell_selected]){
		if(player(myindex())->vitals[VITAL_MP] < spell(player(myindex())->spells[tempdata()->spell_selected])->mpreq){
			//	Call AddText("Not enough MP to cast " & Trim$(Spell(SpellSelected).Name) & ".", 12)
			return;
		}
		if(gettickcount() > player(myindex())->attacktimer + 1){
			if(player(myindex())->moving == 0){
				clear_buffer(&buffer);
				add_opcode(&buffer,CCAST);
				add_buffer(&buffer,&tempdata()->spell_selected, SIZE16);
				socketsend(&buffer);
				player(myindex())->attacking = TRUE;
				player(myindex())->attacktimer = gettickcount();
				tempdata()->castedspell = TRUE;
			}
			else{
				//Call AddText("Cannot cast while walking!", 12)
			}
		}
	}
	else{
		//Call AddText("No spell here.", 12)
	}
}
Exemplo n.º 2
0
boolean openabout (boolean flzoom, long ctreservebytes) {
	
	/*
	2.1b5 dmb: added ctreservebytes parameter. of non-zero, caller wants us to 
	reserve space in the heap below the dialog record (during initialization)
	*/
	
	hdlwindowinfo hinfo;
	
#ifdef MACVERSION
	Ptr ptemp = nil;
	
	if (ctreservebytes > 0)
		ptemp = NewPtr (ctreservebytes); /*force about window to load high*/
#endif

	aboutstart ();
	
	shellpatchnilroutines ();
	
//	aboutwindow = newmodaldialog (128, -1);
	newaboutwindow (true);
	
	if (findaboutwindow (&hinfo))
		shellupdatenow ((**hinfo).macwindow);
	
#ifdef MACVERSION
	if (ptemp != nil)
		DisposePtr (ptemp); /*restore heap space for remaining code segments*/
#endif
	
	aboutopenticks = gettickcount ();
	
	return (true);
	} /*openabout*/
Exemplo n.º 3
0
/**
* check_attack(void)
*
* @brief Check attack
* @param void
* @return void
*/
void check_attack(void)
{
	buffer_t buffer;
	if(tempdata()->control){
		if(player(myindex())->attacktimer + 1 < gettickcount()){
			if(!player(myindex())->attacking){
				player(myindex())->attacking = 1;
				player(myindex())->attacktimer = gettickcount();

				clear_buffer(&buffer);
				add_opcode(&buffer, CATTACK);
				socketsend(&buffer);
			}
		}
	}
}
Exemplo n.º 4
0
boolean opisdraggingmove (Point ptorig, unsigned long origticks) {

	Point ptnew;
	
	getmousepoint (&ptnew);
		
	return ((pointdist (ptorig, ptnew) > draggingpix) || ((gettickcount () - origticks) > draggingticks));
	} /*opisdraggingmove*/
Exemplo n.º 5
0
void setWriteStartBuffer(struct RobotData &robotData, struct InterpolationData &ipoData, struct SCurveParameters &params)
{				
	if (robotData.writeLastBufferIsValid && 
		((gettickcount() - robotData.writeTime) < WRITEBUFFERMAXPAUSE))
	{
		
		//robotData.writeStartBuffer = robotData.writeLastBuffer;
	} else
	robotData.writeStartBuffer = robotData.readBuffer;
}
Exemplo n.º 6
0
void closeabout (boolean flzoom, short minticks) {
	
	hdlwindowinfo hinfo;
	
	if (findaboutwindow (&hinfo)) {
	
		delayticks (aboutopenticks + minticks - gettickcount ());
		
		shellclose ((**hinfo).macwindow, false);
		}
	} /*closeabout*/
Exemplo n.º 7
0
void initRobotData(struct RobotData &robotData)
{
	robotData.writeStartBuffer = robotData.readBuffer;
	robotData.writeBufferIndex = 0; // current index in robotData.writeBuffer
	robotData.writeBufferLength = 0; // number of valid items in robotData.writeBuffer
	
	robotData.readTime = gettickcount(); // timestamp of last read action (from ax12s)
	robotData.writeTime = robotData.readTime; // timestamp of last write action (to ax12s)
	robotData.writeTimeDiffAverage = 0; // average length of one p2p move
	robotData.writeTimeDiffCounter = 0; // current index of robotData.writeTimeDiffs
	
	robotData.writeLastBufferIsValid = false;
	
	robotData.readTimeDiff = 0; // time difference between last two read actions
}
Exemplo n.º 8
0
boolean openabout (boolean flzoom, long ctreservebytes) {
#pragma unused(flzoom)

	/*
	2.1b5 dmb: added ctreservebytes parameter. of non-zero, caller wants us to 
	reserve space in the heap below the dialog record (during initialization)
	*/
	
	hdlwindowinfo hinfo;
	
#ifdef MACVERSION
	Ptr ptemp = nil;
	
	if (ctreservebytes > 0)
		ptemp = NewPtr (ctreservebytes); /*force about window to load high*/
#endif

	aboutstart ();
	
	shellpatchnilroutines ();
	
//	aboutwindow = newmodaldialog (128, -1);
	newaboutwindow (true);
	
	if (findaboutwindow (&hinfo))
	{
		shellupdatenow ((**hinfo).macwindow);
		//Code change by Timothy Paustian 10/5/00
		//We need to flush the about window to the screen
		//safe because this routine only gets call during init. 
		#if TARGET_API_MAC_CARBON == 1
		QDFlushPortBuffer(GetWindowPort((**hinfo).macwindow), nil);
		#endif
	}
#ifdef MACVERSION
	if (ptemp != nil)
		DisposePtr (ptemp); /*restore heap space for remaining code segments*/
#endif
	
	aboutopenticks = gettickcount ();
	
	return (true);
	} /*openabout*/
Exemplo n.º 9
0
/**
* game loop(void)
*
* @brief Game loop function
* @param void
* @return void
*/
void gameloop(void)
{
	uint32 i = 0;

	tick = gettickcount();

	if(tmr25 < tick){
		if(tempdata()->canmovenow){
			check_movement();
			check_attack();
		}

		if(tempdata()->mapanimtimer < tick){
			if(tempdata()->mapanim)
				tempdata()->mapanim = FALSE;
			else
				tempdata()->mapanim = TRUE;
			tempdata()->mapanimtimer = tick + .250;
		}

		tmr25 = tick + .025;
	}

	if(walktimer < tick){
		for( i = 0; i < players_on_map(); i++){
			if(player(player_on_map(i))->moving > 0)
				process_movement(player_on_map(i));
		}

		for( i = 0; i < MAX_MAP_NPCS; i++){
			if(map()->npc[i].num){
				if(map()->npc[i].moving)
					process_npc_movement(i);
			}
		}

		walktimer = tick + .030;
	}
}
Exemplo n.º 10
0
void server_loop(void)
{
	double  tick;
	double  tmr500 = 0;
	double  tmr1000 = 0;
	double  lastupdatesaveplayers = 0;
	double  lastupdatemapspawnitems = 0;
	double  lastupdateplayervitals = 0;

	while(server_is_online){
		tick = gettickcount();

		if(tick > tmr500){
			update_npc_ai();

			tmr500 = gettickcount() + .5;
		}

		if(tick > tmr1000){
			if(shutting_down())
				handle_shutdown();

			tmr1000 = gettickcount() + 1;
		}

		if(tick > lastupdateplayervitals){
			update_player_vitals();
			lastupdateplayervitals = gettickcount() + 5;
		}

		if(tick > lastupdatemapspawnitems){
			update_map_spawn_items();
			lastupdatemapspawnitems = gettickcount() + 30;
		}

		if(tick > lastupdatesaveplayers){
			update_save_players();
			lastupdatesaveplayers = gettickcount() + 60;
		}
	}
	return;
}
Exemplo n.º 11
0
void update_npc_ai(void)
{
	uint8 i = 0;
	uint32 mapnum = 1;
	uint8 mapnpcnum = 0;
	uint16 npcnum, target;
	double  tickcount;
	uint32 damage;
	char *string = NULL;

	for(mapnum = 1; mapnum < MAX_MAPS; mapnum++){
		if(players_on_map(mapnum)){
			tickcount = gettickcount();

			for(mapnpcnum = 0; mapnpcnum < MAX_MAP_NPCS; mapnpcnum++){
				npcnum = map(mapnum)->npc[mapnpcnum].num;

				if(npcnum > 0){
					target = map(mapnum)->npc[mapnpcnum].target;

					ai_attack_on_sight(mapnpcnum, target, mapnum);

					if(npc(npcnum)->behavior != BEHAVIOR_SHOPKEEPER){
						if(target > 0){
							if(temp_player(target)->loggedin && player(target)->map == mapnum){
								ai_npc_collision(ai_npc_move(mapnum, mapnpcnum, target), mapnum, mapnpcnum, target);

								if(can_npc_attack_player(mapnpcnum,target)){
									if(!can_player_block_hit(target)){
										damage = npc(npcnum)->stat[STAT_STRENGTH] - get_player_protection(target);
										npc_attack_player(mapnpcnum, target, damage);
									}
									else{
										string = comb_4str(item(player(target)->inv[player(target)->equipment[EQUIPMENT_SHIELD]].id)->name, " blocks the ", npc(npcnum)->name,"'s hit!");
										player_msg(target, string, 1); //bright cyan
									}
								}
								else
									map(mapnum)->npc[mapnpcnum].target = 0;
							}
							else
								map(mapnum)->npc[mapnpcnum].target = 0;
						}
					}
					else{
						if((rand() % 4) == 1){
							i = rand() % 4;

							if(can_npc_move(mapnum,mapnpcnum, i))
								npc_move(mapnum,mapnpcnum,i);
						}
					}

					ai_hp_regen(tickcount, mapnum, mapnpcnum);

					if(tickcount > map(mapnum)->npc[mapnpcnum].spawnwait + npc(map(mapnum)->npc[mapnpcnum].num)->spawnsecs * 1000)
						spawn_npc(mapnpcnum, mapnum);
				}
			}
		}
	}
}
Exemplo n.º 12
0
void RVExtension(char *output, int outputSize, const char *function)
{
	char *stopstring;
	size_t funlen;

	if (output == NULL || outputSize <= 0 || function == NULL) return;
	funlen = strnlen(function, FUNCTIONSIZE + 2);	// "<n>:<OCCx string>"
	if (funlen == 0) return;
	if (funlen == FUNCTIONSIZE + 2) return;

	*output = '\0';

	//asmlog(LOG_INFO, "RVExtension(%p, %d, \"%s\")", output, outputSize, function);
	if (!isdigit(*function)) {
		do {
			// Get version
			if (strncasecmp(function, "version", sizeof("version")) == 0) {
				snprintf(output, outputSize, "%s", ASM_VERSION); // return the RV extension version
				break;
			}
			// (Debug) Get instance id
			if (strncasecmp(function, "id", sizeof("id")) == 0) {
				snprintf(output, outputSize, "%zd", InstanceID);
				break;
			}
		} while (0);
		output[outputSize - 1] = '\0';
		return;
	} else {
		// function is supposed to be <digit>:<data>
		if (function[1] != ':' || funlen < 3) {
			return;
		}
	}

	if (!FileMap) {
	   asmlog(LOG_ERR, "no FileMap");
	   return;
	}

	switch (*function) {
		case '0': // FPS update
			if (ArmaServerInfo != NULL) {
					unsigned FPS,FPSMIN;

					FPS = strtol(&function[2], &stopstring, 10);
					FPSMIN = strtol(&stopstring[1], &stopstring, 10);
					ArmaServerInfo->SERVER_FPS    =	FPS;
					ArmaServerInfo->SERVER_FPSMIN =	FPSMIN;
					ArmaServerInfo->TICK_COUNT    = gettickcount();

					asmlog(LOG_DEBUG, "0: FPS update");
			}
			break;

		case '1': // CPS update
			if (ArmaServerInfo != NULL) {
					struct timespec PCE;
					double tnsec;
					unsigned conditionNo;

					clock_gettime(CLOCK_MONOTONIC, &PCE);
					tnsec = (double)((1000000000 * PCE.tv_sec + PCE.tv_nsec) - (1000000000 * PCS.tv_sec + PCS.tv_nsec))/(double)(1000000000 * PCF.tv_sec + PCF.tv_nsec);
					conditionNo = strtol(&function[2], &stopstring, 10);
					ArmaServerInfo->FSM_CE_FREQ = floor(conditionNo * 1000 / tnsec + 0.5);

					PCS = PCE;
					asmlog(LOG_DEBUG, "1: CPS update");
			}
			break;

		case '2': // GEN update
			if (ArmaServerInfo != NULL) {
				unsigned players, ail, air;
				FILE* f = NULL;
				long rss = 0L;

				players = strtol(&function[2],   &stopstring, 10);
				ail		= strtol(&stopstring[1], &stopstring, 10);
				air		= strtol(&stopstring[1], &stopstring, 10);
				ArmaServerInfo->PLAYER_COUNT = players;
				ArmaServerInfo->AI_LOC_COUNT = ail;
				ArmaServerInfo->AI_REM_COUNT = air;

				// ASMdll.dll for Windows gets the "Commit Charge" value here,
				// the total memory that the memory manager has committed
				// for a running process. (unit: bytes)
				if ((f = fopen("/proc/self/statm", "r")) != NULL) {
					// The second number in statm is the size of the in-memory
					// working set (RSS). TODO: is this the value we want?
					if (fscanf(f, "%*s%8ld", &rss) != 1) {
						rss = 0L;
					}
					fclose(f);
				}
				ArmaServerInfo->MEM = rss * pagesize;
				asmlog(LOG_DEBUG, "2: GEN update");
			}
			break;

		case '3': // MISSION update
			if (ArmaServerInfo != NULL) {
				memset(ArmaServerInfo->MISSION, 0, SMALSTRINGSIZE);
				strncpy(ArmaServerInfo->MISSION, &function[2], SMALSTRINGSIZE);
				ArmaServerInfo->MISSION[SMALSTRINGSIZE-1] = 0;
				asmlog(LOG_DEBUG, "3: MISSION update");
			}
			break;

		case '4': // OBJ_COUNT_0 update
			if (ArmaServerInfo != NULL) {
				unsigned obj;
				obj = strtol(&function[2], &stopstring, 10);
				ArmaServerInfo->OBJ_COUNT_0 = obj;
				asmlog(LOG_DEBUG, "4: OBJ_COUNT_0 update");
			}
			break;

		case '5': // OBJ_COUNT_1 update
			if (ArmaServerInfo != NULL) {
				unsigned obj;
				obj = strtol(&function[2], &stopstring, 10);
				ArmaServerInfo->OBJ_COUNT_1 = obj;
				asmlog(LOG_DEBUG, "5: OBJ_COUNT_1 update");
			}
			break;

		case '6': // OBJ_COUNT_2 update
			if (ArmaServerInfo != NULL) {
				unsigned obj;
				obj = strtol(&function[2], &stopstring, 10);
				ArmaServerInfo->OBJ_COUNT_2 = obj;
				asmlog(LOG_DEBUG, "6: OBJ_COUNT_2 update");
			}
			break;

		case '9': // init
			if (ArmaServerInfo == NULL) {
				if (enableProfilePrefixSlotSelection > 0 && isdigit(function[2])) {
					asmlog(LOG_DEBUG, "selecting slot based on profileName...");
					// Select the instance based on the leading digit in the server's profile name
					errno = 0;
					InstanceID = strtol(&function[2], &stopstring, 10);
					if (errno == 0 && InstanceID < MAX_ARMA_INSTANCES) {
						ArmaServerInfo = (struct ARMA_SERVER_INFO*)((unsigned char *)FileMap + (InstanceID * pagesize));
					}
				} else {
					asmlog(LOG_DEBUG, "finding available slot");
					// Find a free server info slot or re-use one if it hasn't been updated in the last 10 seconds
					uint32_t DeadTimeout = gettickcount() - 10000;
					for (InstanceID = 0 ; InstanceID < MAX_ARMA_INSTANCES ; InstanceID++) {
						ArmaServerInfo = (struct ARMA_SERVER_INFO*)((unsigned char *)FileMap + (InstanceID * pagesize));
						if ((ArmaServerInfo->PID == 0) || (ArmaServerInfo->TICK_COUNT < DeadTimeout)) break;
					}
				}
				if (ArmaServerInfo != NULL && InstanceID < MAX_ARMA_INSTANCES) {
					ArmaServerInfo->MEM = 0;
					ArmaServerInfo->TICK_COUNT = gettickcount();
					ArmaServerInfo->PID = getpid();
					memset(ArmaServerInfo->PROFILE, 0, sizeof(ArmaServerInfo->PROFILE));
					strncpy(ArmaServerInfo->PROFILE, &function[2], sizeof(ArmaServerInfo->PROFILE));
					ArmaServerInfo->PROFILE[sizeof(ArmaServerInfo->PROFILE) - 1] = '\0';
					asmlog(LOG_INFO, "init successful, pid %zd, using slot %d", ArmaServerInfo->PID, InstanceID);
					snprintf(output, outputSize, "_ASM_OPT=[%s,%s,%s,\"%s\",\"%s\",\"%s\"];", OCI0, OCI1, OCI2, OCC0, OCC1, OCC2);
				} else {
					ArmaServerInfo = NULL;
					asmlog(LOG_ERR, "init failed - no available slots.");
					snprintf(output, outputSize, "_ASM_OPT=[0,0,0,\"\",\"\",\"\"];");
				}
				output[outputSize - 1] = '\0';
			} else {
				ArmaServerInfo->MEM = 0;
			}
			break;

		default: // 7,8 are not implemented
			return;
	}
	if (ArmaServerInfo != NULL) {
		if (msync(ArmaServerInfo, pagesize, MS_ASYNC|MS_INVALIDATE) != 0) {
			asmlog(LOG_ERR, "msync(): %s", strerror(errno));
		}
	}
	return;
}
Exemplo n.º 13
0
void shellhandlekeystroke (void) {
	
	/*
	if it's a cmd-key we first offer it to the frontmost window, if he doesn't
	consume it, we pass it on to the menubar.
	
	if it's shift-enter, we close the frontmost window.
	
	otherwise we pass the keystroke to the front window's handler.
	
	7/18/90 DW: add hooks.  they're allowed to consume a keystroke by returning
	false.
	
	11/8/90 DW: add support for style keys -- cmd-shift BIOUS.
	
	12/6/91 dmb: give menubar priority over cmdkeyfilter
	*/
	
	unsigned int chkb;
	#ifdef MACVERSION	
		register boolean fl;
		long codeword;
	#endif
	
	timelastkeystroke = gettickcount ();
	
	setkeyboardstatus (shellevent.message, shellevent.what, shellevent.modifiers); /*fill keyboardstatus record with info about the event*/
	
	if (!keyboardstatus.flautokey)	/*4.0b7 dmb: new non-repeating ouchs*/
		flouchlocked = false;

#ifdef MACVERSION	
	if (shellfilterfunctionkey (&codeword) || shellfilterfontkey (&codeword)) {
		
		fl = shellpushfrontglobals ();
		
		shellupdatemenus ();
		
		HiliteMenu (HiWord (codeword));
		
		shellhandlemenu (codeword);
		
		if (fl)
			shellpopglobals ();
			
		return;
		}
#endif
	
	if (!shellcallkeyboardhooks ())
		return;
	
	chkb = keyboardstatus.chkb; /*move into register*/

#ifdef MACVERSION	
	if (keyboardstatus.flcmdkey && (chkb >= chspace)) {
		
		if (chkb == '.') { /*cmd-period is consumed here*/
		
			keyboardsetescape ();
			
			return;
			}
		
		/*
		if (shellpushfrontglobals ()) { /%a window is open%/
			
			fl = (*shellglobals.cmdkeyfilterroutine) (keyboardstatus.chkb);
			
			shellpopglobals ();
			
			if (!fl) /%cmd-key was consumed%/
				return;
			}
		*/
		
		fl = shellpushfrontglobals ();
		
		shellupdatemenus (); /*be sure the menus are properly checked and highlighted*/
		
		if (!shellhandlemenu (MenuKey (chkb))) { /*cmd-key not consumed by menubar*/
			
			if (fl)
				(*shellglobals.cmdkeyfilterroutine) (chkb);
			}
		
		if (fl)
			shellpopglobals ();
		
		return;
		}
#endif
		
	if (shellpushfrontglobals ()) { /*a window is open to close or receive keystroke*/
	
		if (shellcalleventhooks (&shellevent, shellwindow)) /*keystroke wasn't consumed*/
			(*shellglobals.keystrokeroutine) ();
		
		shellpopglobals ();
		}
	} /*shellhandlekeystroke*/
Exemplo n.º 14
0
static boolean minimousedown (Point pt, tyclickflags flags) {
	
	register hdlminirecord hm = minidata;
	short item;	
	Rect r;	
	
	minicheckselectall (); /*if a selectall is pending, do it now*/
	
	item = minifindtextobject (pt);
	
	if (item >= 0) {
		
		miniactivatemessage (false);
		
		(**hm).activetextitem = item;
		
		if (!minisetwpglobals (item))
			return (false);
		
		wpclick (pt, flags);
		
		(*(**hm).texthitroutine) (pt);
		
		shellevent.when = gettickcount ();
		
		mouseup (shellevent.when, shellevent.where.h, shellevent.where.v, shellevent.what); /*textedit may swallow the mouseup event when tracking click*/
		
		return (true);
		}
	
	if (pointinrect (pt, (**hm).msgrect)) {
		
		if (minisetactivewpglobals ())
			wpactivate (false);
		
		(**hm).activetextitem = -1;

		miniactivatemessage (true);
		}

	r = (**hm).iconrect;
	
	if (pointinrect (pt, r)) {
		
		if ((**hm).fliconenabled)
			if (trackicon (r, minidrawicon))
				return (miniiconhit (false));
		
		return (true);
		}
	
	bundle { /*check for mousedown in a popup*/
		
		register short x;
		
		x = minifindpopup (pt);
		
		if (x >= 0) { /*mousedown was in a popup*/
			
			return (minipopuphit (x));
			}
		}
	
	/*
	ouch ();
	*/
	
	return (true);
	} /*minimousedown*/
Exemplo n.º 15
0
/**
* can_move(void)
*
* @brief Determine if player is able to move
* @param void
* @return void
*/
sbool can_move(void)
{
	uint32 d;
	sbool ismap = FALSE;

	if(player(myindex())->moving)
		return FALSE;

	if(tempdata()->castedspell){
		if(gettickcount() > player(myindex())->attacktimer + 1)
			tempdata()->castedspell = FALSE;
		else
			return FALSE;
	}

	d = player(myindex())->dir;

	switch(tempdata()->dir){
	case DIR_NONE: return FALSE;
	case DIR_UP:
		player(myindex())->dir = DIR_UP;

		if(player(myindex())->y <= 0){
			if(map()->up) ismap = TRUE;
			return FALSE;
		}
		break;
	case DIR_DOWN:
		player(myindex())->dir = DIR_DOWN;

		if(player(myindex())->y >= MAX_MAPY - 1){
			if(map()->down) ismap = TRUE;
			return FALSE;
		}
		break;
	case DIR_LEFT:
		player(myindex())->dir = DIR_LEFT;

		if(player(myindex())->x <= 0){
			if(map()->left) ismap = TRUE;
			return FALSE;
		}
		break;

	case DIR_RIGHT:
		player(myindex())->dir = DIR_RIGHT;

		if(player(myindex())->x >= MAX_MAPX - 1){
			if(map()->right) ismap = TRUE;
			return FALSE;
		}
		break;
	}

	if(ismap){
		//map_editor_leave_map();
		request_new_map();
		tempdata()->gettingmap = TRUE;
		tempdata()->canmovenow = FALSE;
		return FALSE;
	}

	if(check_direction(player(myindex())->dir)){
		if(d != player(myindex())->dir)
			send_player_dir();

		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 16
0
void opdraggingmove (Point ptstart, hdlheadrecord hsource) {
	
	/*
	9/22/93 dmb: need to validate a drag just like a copy. also need to 
	provide for client sorting, like a paste
	*/
	
	long tc = 0;
	tyhotspot hotspot;
	Point pt;
	tydirection dir;
	
	if (!((**outlinedata).validatecopycallback) (STR_move))
		return;
	
	clearbytes ((ptrchar) &hotspot, longsizeof (hotspot));
	
	hotspot.pt = ptstart;
	
	hotspot.hsource = hsource;
	
	/*
	opgetwindowhandle (pt, &hotspot.sourcewindowhandle);
	
	hotspot.destwindowhandle = hotspot.sourcewindowhandle;
	*/
	
	if (true /*claystartdrag(ptstart, hsource) != noErr*/) {
		
		while (mousestilldown ()) {
			
			getmousepoint (&pt);
			
			#if false
			
				Handle currentwindow;
			
				if (!pointinrect (pt, (*FrontWindow ()).portRect))
					Debugger ();
			
				opgetwindowhandle (pt, &currentwindow);
				
				if (currentwindow != hotspot.destwindowhandle) { /*pointing into another window*/
					
					opsetwindowhandlecontext (hotspot.destwindowhandle);
			
					operasehotspot (&hotspot);
					
					hotspot.destwindowhandle = currentwindow;
					
					opsetwindowhandlecontext (hotspot.destwindowhandle);
			
					opupdatehotspot (ptstart, pt, &hotspot);
					}
			#endif
			
			if ((gettickcount () - tc) > draggingscrollrate) {
				
				if (mousecheckautoscroll (pt, (**outlinedata).outlinerect, false, &dir)) {
				
					opscrollfordrag (&hotspot, dir);
					
					tc = gettickcount ();
					}
				}
			
			opupdatehotspot (ptstart, pt, &hotspot);
			} /*while*/
		
		operasehotspot (&hotspot); /*user let up on the button*/
	
		opmovetohotspot (&hotspot);
		}  // if noErr
	} /*opdraggingmove*/
Exemplo n.º 17
0
byte doInterpolation(DynamixelComm *dc, struct RobotData &robotData, struct InterpolationData &ipoData, struct SCurveParameters &params)
{
	byte failure = AX12_NOERROR;
	unsigned long tmpTime = gettickcount();
	
	if (tmpTime >= robotData.readTime + ipoData.ipoPause)
	{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
		robotData.readTimeDiff = tmpTime - robotData.readTime;
		robotData.readTime = tmpTime;

		//printf("past the time - %ld, pause = %ld\n", tmpTime, ipoData.ipoPause);
		
		// read or write every ipoData.ipoPause Milliseconds
		if (ipoData.ipoCounter <= ipoData.ipoMax)
		{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
			// if at least two points are available
			if ((robotData.writeBufferLength > ipoData.ipoParam) && ipoData.preparationDone)
			{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
				/*
				if (!ipoData.preparationDone)
				{
					setWriteStartBuffer(robotData, ipoData, params);
				
					// preprocessing
					doPreparation(robotData, ipoData, params);
				}
				*/
				
				// write (interpolated) data to servos
				doWriteData(dc, robotData, ipoData, params);
				
				// remove data from robotData.writeBuffer at end of interpolation cycle
				if (ipoData.ipoCounter >= ipoData.ipoMax)
				{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
					while(gettickcount() < tmpTime + ipoData.ipoPause)
						;

					ipoData.preparationDone = false;
					
					robotData.writeBufferLength--;
					byte oldWriteBufferIndex = robotData.writeBufferIndex;
					robotData.writeBufferIndex = (robotData.writeBufferIndex + 1) % WRITEBUFFERMAX;
					
					// copy processed write target to last buffer
					// modified:
					//memcpy(robotData.writeLastBuffer, &robotData.writeBuffer[oldWriteBufferIndex][0], AX12_COUNT*AX12_DATA_WRITE*sizeof(byte));
					robotData.writeStartBuffer = &robotData.writeBuffer[oldWriteBufferIndex][0];
					robotData.writeLastBufferIsValid = true;
					
					if (robotData.writeBufferLength > 0)
					{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
						// modified:
						//robotData.writeStartBuffer = robotData.writeLastBuffer;
						
						// preprocessing
						printf("doPreparation inner\n");
						doPreparation(robotData, ipoData, params);
					}
					
					// stuff read op between this and the next write op
					
					// modified:
					robotData.readTime -= ipoData.ipoPause / 2;
					//robotData.readTime -= (ipoData.ipoPause * 3)/ 4;
					
					// calc average length of one write cycle
					tmpTime = robotData.writeTime;
					robotData.writeTime = gettickcount();
					
					if ((robotData.writeTime - tmpTime) < WRITEBUFFERMAXPAUSE)
					{
						printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
						robotData.writeTimeDiffAverage = (unsigned int) (0.7 * (float)robotData.writeTimeDiffAverage + 
															0.3 * (float) (robotData.writeTime - tmpTime));
		
						if (ipoData.ipoPauseAutoSet)
						{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
							float tmp = ((float)ipoData.ipoTotalTime * (float)ipoData.ipoTotalTime)/ ((float)ipoData.ipoMax * (float)robotData.writeTimeDiffAverage);
							if (robotData.writeBufferLength > 1)
							{	
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
								float tmp2 = (float) (robotData.writeBufferLength-1);
							
								tmp *= 1.0 - ipoData.ipoAutoAdjustParameter + 
								ipoData.ipoAutoAdjustParameter*(1-(tmp2 * tmp2)/64.0);
							}
							ipoData.ipoPause = (unsigned long) (tmp + 0.5);
						}
					}
					
					/*
					if ((robotData.writeTime - tmpTime) < WRITEBUFFERMAXPAUSE)
					{
						robotData.writeTimeDiffs[robotData.writeTimeDiffCounter] = (robotData.writeTime - tmpTime);
		
						if (robotData.writeTimeDiffs[robotData.writeTimeDiffCounter] > WRITETIMEDIFFMAX)
							robotData.writeTimeDiffs[robotData.writeTimeDiffCounter] = WRITETIMEDIFFMAX;
							
						robotData.writeTimeDiffCounter++;
						if (robotData.writeTimeDiffCounter == WRITETIMEDIFFLEN)
						{
							robotData.writeTimeDiffCounter = 0;
							robotData.writeTimeDiffAverage = (unsigned int) (getTrimmedAverage(robotData.writeTimeDiffs, WRITETIMEDIFFLEN, WRITETIMEDIFFREMOVE));
						}
						
						if (ipoData.ipoPauseAutoSet)
						{
							float tmp = ((float)ipoData.ipoTotalTime * (float)ipoData.ipoTotalTime)/ ((float)ipoData.ipoMax * (float)robotData.writeTimeDiffAverage);
							if (robotData.writeBufferLength > 1)
							{	
								float tmp2 = (float) (robotData.writeBufferLength-1);
							
								tmp *= 1.0 - ipoData.ipoAutoAdjustParameter + 
								ipoData.ipoAutoAdjustParameter*(1-(tmp2 * tmp2)/64.0);
							}
							ipoData.ipoPause = (unsigned int) (tmp + 0.5);
						}
						robotData.writeTimeDiffAverage = ((unsigned int)((float)robotData.writeTimeDiffAverage / (float)ipoData.ipoPause + 0.5)) * ipoData.ipoPause;
					}
					*/
				}
			}
		} 
		// modified:
		else
		// read ax12 data every (ipoData.ipoMax + 1) +ipoData.ipoPause Milliseconds
		//if (ipoData.ipoCounter >= ipoData.ipoMax)
		{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
			failure = AX12_NOERROR;
			if (!ipoData.preparationDone) // comment this line in order to produce position feedback during write actions
			{
		printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
				readPositionData(dc, robotData.readBuffer, failure);
			}
			
			
			if (failure != AX12_NOERROR)
			{
				printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
				robotData.readTime = gettickcount() - ipoData.ipoPause + AX12_READERROR_TIMEOUT;
				return failure;
			}
				
			
			ipoData.ipoCounter = 0;
			
			if (failure == AX12_NOERROR)
			if (!ipoData.preparationDone)
			{
				printf("%s:%d\n",__func__,__LINE__);
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
				setWriteStartBuffer(robotData, ipoData, params);
			
				// preprocessing
				printf("doPreparation outer\n");
		testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
				doPreparation(robotData, ipoData, params);
			} 
			// stuff read op between two write ops 
			
			// modified:
			robotData.readTime -= ipoData.ipoPause / 2;
			//robotData.readTime -= ipoData.ipoPause / 4;
		} 
		
		ipoData.ipoCounter++;
	}	

	testWB(robotData.writeBuffer[robotData.writeBufferIndex],__LINE__);
	
	return failure;
}
Exemplo n.º 18
0
static boolean langerrormousedown (Point pt, tyclickflags flags) {
#pragma unused (flags)

	/*
	7/16/90 DW: wired off the consumption of the error callback, if you want
	it back on, just switch on the code that's commented out, and the script
	icon will go dim, the cursor adjustment won't happen, and no mouseclicks
	will be handled for clicking on the script button.
	
	4.1b4 dmb: use custom tracking code so we can popup a menu after mouse has
	been down a fraction of a second.
	*/
	
	register hdllangerrorrecord hle = langerrordata;
	Rect r;
	boolean flinrectnow, flwasinrect;
	boolean flconsumed = false;
	unsigned long timemoved;
	short threshhold = getmousedoubleclicktime () * 2 / 3;
	
	if ((**hle).flcallbackconsumed)
		return (false);
	
	r = (**hle).iconrect;
	
	if (pointinrect (pt, r)) {
		
		setcursortype (cursorisarrow); /*get rid of funny appendage*/
		
		langerrordrawicon (true); /*show icon in depressed state*/
		
	//	if (!mousetrack (r, langerrordrawicon)) /*if false, mouse didn't stay in rectangle*/
	//		return (false);
		
		flwasinrect = true; /*at least for the first iteration of loop*/
		
		timemoved = gettickcount ();
		
		while (mousestilldown ()) { /*stay in holding pattern*/
		
			getmousepoint (&pt);
			
			flinrectnow = pointinrect (pt, r);
			
			if (flinrectnow != flwasinrect)	{
			
				langerrordrawicon (flinrectnow);
				
				timemoved = gettickcount ();
				}
			else if (flinrectnow && gettickcount () - timemoved > (unsigned) threshhold) {
				
				langerrorpopupmenu ();
				
				flconsumed = true;
				}
			
			flwasinrect = flinrectnow;
			} /*while*/
		
		if (flwasinrect) {
		
			langerrordrawicon (false); /*show icon in un-depressed state*/
			
			if (!flconsumed)
				langerrorbuttonhit ();
			}
		}
	
	return (true);
	} /*langerrormousedown*/