static void key_init (void) { int i; pool = allocate_key_chunk (); (void)SDL_GetKeyState (&num_sdl_keys); bindings = (keybinding **) HMalloc (sizeof (keybinding *) * num_sdl_keys); for (i = 0; i < num_sdl_keys; i++) bindings[i] = NULL; #ifdef HAVE_JOYSTICK /* Prepare for possible joystick controls. We don't actually GRAB joysticks unless we're asked to make a joystick binding, though. */ joycount = SDL_NumJoysticks (); if (joycount) { joysticks = HMalloc (sizeof (joystick) * joycount); for (i = 0; i < joycount; i++) { joysticks[i].stick = NULL; joysticks[i].numaxes = joysticks[i].numbuttons = 0; joysticks[i].axes = NULL; joysticks[i].buttons = NULL; joysticks[i].threshold = 10000; } } else { joysticks = NULL; } #else joycount = 0; #endif /* HAVE_JOYSTICK */ }
Thread CreateThread_SDL (ThreadFunction func, void *data, SDWORD stackSize #ifdef NAMED_SYNCHRO , const char *name #endif ) { TrueThread thread; struct ThreadStartInfo *startInfo; thread = (struct _thread *) HMalloc (sizeof *thread); #ifdef NAMED_SYNCHRO thread->name = name; #endif #ifdef PROFILE_THREADS thread->startTime = GetTimeCounter (); #endif thread->localData = CreateThreadLocal (); startInfo = (struct ThreadStartInfo *) HMalloc (sizeof (*startInfo)); startInfo->func = func; startInfo->data = data; startInfo->sem = SDL_CreateSemaphore (0); startInfo->thread = thread; thread->native = SDL_CreateThread (ThreadHelper, (void *) startInfo); if (!(thread->native)) { DestroyThreadLocal (thread->localData); HFree (startInfo); HFree (thread); return NULL; } // The responsibility to free 'startInfo' and 'thread' is now by the new // thread. QueueThread (thread); #ifdef DEBUG_THREADS #if 0 log_add (log_Debug, "Thread '%s' created.", ThreadName (thread)); fflush (stderr); #endif #endif // Signal to the new thread that the thread structure is ready // and it can begin to use it. SDL_SemPost (startInfo->sem); (void) stackSize; /* Satisfying compiler (unused parameter) */ return thread; }
static void create_joystick (int index) { SDL_Joystick *stick; int axes, buttons, hats; if (index >= joycount) { log_add (log_Warning, "VControl warning: Tried to open a non-existent joystick!"); return; } if (joysticks[index].stick) { // Joystick is already created. Return. return; } stick = SDL_JoystickOpen (index); if (stick) { joystick *x = &joysticks[index]; int j; log_add (log_Info, "VControl opened joystick: %s", SDL_JoystickName (index)); axes = SDL_JoystickNumAxes (stick); buttons = SDL_JoystickNumButtons (stick); hats = SDL_JoystickNumHats (stick); log_add (log_Info, "%d axes, %d buttons, %d hats.", axes, buttons, hats); x->numaxes = axes; x->numbuttons = buttons; x->numhats = hats; x->axes = HMalloc (sizeof (axis_type) * axes); x->buttons = HMalloc (sizeof (keybinding *) * buttons); x->hats = HMalloc (sizeof (hat_type) * hats); for (j = 0; j < axes; j++) { x->axes[j].neg = x->axes[j].pos = NULL; } for (j = 0; j < hats; j++) { x->hats[j].left = x->hats[j].right = NULL; x->hats[j].up = x->hats[j].down = NULL; x->hats[j].last = SDL_HAT_CENTERED; } for (j = 0; j < buttons; j++) { x->buttons[j] = NULL; } x->stick = stick; } else { log_add (log_Warning, "VControl: Could not initialize joystick #%d", index); } }
void SerializeCeosRecordsFromFile(Link_t *record_list, VSILFILE *fp) { CeosRecord_t *crec; Link_t *Link; while(!VSIFEofL(fp)) { crec = HMalloc(sizeof(CeosRecord_t)); VSIFReadL(crec,sizeof(CeosRecord_t),1,fp); crec->Buffer = HMalloc(crec->Length * sizeof(char) ); VSIFReadL(crec->Buffer,sizeof(char),crec->Length,fp); Link = ceos2CreateLink(crec); AddLink(record_list,Link); } }
TFB_Image * TFB_DrawImage_New (TFB_Canvas canvas) { TFB_Image *img = HMalloc (sizeof (TFB_Image)); img->mutex = CreateMutex ("image lock", SYNC_CLASS_VIDEO); img->ScaledImg = NULL; img->MipmapImg = NULL; img->FilledImg = NULL; img->colormap_index = -1; img->colormap_version = 0; img->NormalHs = NullHs; img->MipmapHs = NullHs; img->last_scale_hs = NullHs; img->last_scale_type = -1; img->last_scale = 0; img->dirty = FALSE; TFB_DrawCanvas_GetExtent (canvas, &img->extent); if (TFB_DrawCanvas_IsPaletted (canvas)) { img->NormalImg = canvas; } else { img->NormalImg = TFB_DrawCanvas_ToScreenFormat (canvas); } return img; }
static inline TFB_ColorMap * alloc_colormap (void) // returns an addrefed object { TFB_ColorMap *map; if (poolhead) { // have some spares map = poolhead; poolhead = map->next; --poolcount; } else { // no spares, need a new one map = HMalloc (sizeof (*map)); map->palette = AllocNativePalette (); if (!map->palette) { HFree (map); return NULL; } } map->next = NULL; map->index = -1; map->refcount = 1; map->version = 0; return map; }
void InitCeosRecordWithHeader(CeosRecord_t *record, uchar *header, uchar *buffer) { if(record && buffer && header) { if( record->Length != 0 ) record->Length = DetermineCeosRecordBodyLength( header ); if(record->Length < CEOS_HEADER_LENGTH || (record->Buffer = HMalloc(record->Length)) == NULL) { record->Length = 0; return; } /* First copy the header then the buffer */ memcpy(record->Buffer,header,CEOS_HEADER_LENGTH); /* Now we copy the rest */ if( record->Length > CEOS_HEADER_LENGTH ) memcpy(record->Buffer+CEOS_HEADER_LENGTH,buffer,record->Length-CEOS_HEADER_LENGTH); /* Now we fill in the rest of the structure! */ memcpy(&(record->TypeCode.Int32Code),header+TYPE_OFF,sizeof(record->TypeCode.Int32Code)); CeosToNative(&(record->Sequence),header+SEQUENCE_OFF,sizeof(record->Sequence), sizeof( record->Sequence ) ); } }
RandomContext * RandomContext_New (void) { RandomContext *result = (RandomContext *) HMalloc (sizeof (RandomContext)); result->seed = 12345; return result; }
RandomContext * RandomContext_Copy (const RandomContext *source) { RandomContext *result = (RandomContext *) HMalloc (sizeof (RandomContext)); *result = *source; return result; }
void AddRecipe( int (*function)(CeosSARVolume_t *volume, void *token), void *token, const char *name ) { RecipeFunctionData_t *TempData; Link_t *Link; TempData = HMalloc( sizeof( RecipeFunctionData_t ) ); TempData->function = function; TempData->token = token; TempData->name = name; Link = ceos2CreateLink( TempData ); if( RecipeFunctions == NULL) { RecipeFunctions = Link; } else { RecipeFunctions = InsertLink( RecipeFunctions, Link ); } }
static joy_char_t * LoadJoystickAlpha (STRING String, int *count) { UNICODE *str; int c; int i; joy_char_t *chars; UNICODE *cur; *count = 0; str = GetStringAddress (String); if (!str) return 0; c = utf8StringCount (str); chars = HMalloc (c * sizeof (*chars)); if (!chars) return 0; for (i = 0, cur = str; i < c; ++i) { int len = ReadOneChar (chars + i, cur); cur += len; } *count = c; return chars; }
static void ExtractInt(CeosRecord_t *record, int type, unsigned int offset, unsigned int length, int *value) { void *buffer; char format[32]; buffer = HMalloc( length + 1 ); switch(type) { case __CEOS_REC_TYP_A: sprintf( format, "A%u", length ); GetCeosField( record, offset, format, buffer ); *value = atoi( buffer ); break; case __CEOS_REC_TYP_B: sprintf( format, "B%u", length ); #ifdef notdef GetCeosField( record, offset, format, buffer ); if( length <= 4 ) CeosToNative( value, buffer, length, length ); else *value = 0; #else GetCeosField( record, offset, format, value ); #endif break; case __CEOS_REC_TYP_I: sprintf( format, "I%u", length ); GetCeosField( record, offset, format, value ); break; } HFree( buffer ); }
static void GetCodeResData (const char *ship_id, RESOURCE_DATA *resdata) { BYTE which_res; void *hData; which_res = atoi (ship_id); hData = HMalloc (sizeof (CODERES_STRUCT)); if (hData) { RaceDescInitFunc initFunc = CodeResToInitFunc (which_res); RACE_DESC *RDPtr = (initFunc == NULL) ? NULL : (*initFunc)(); if (RDPtr == 0) { HFree (hData); hData = 0; } else { CODERES_STRUCT *cs; cs = (CODERES_STRUCT *) hData; cs->data = *RDPtr; // Structure assignment. } } resdata->ptr = hData; }
int TFB_InitInput (int driver, int flags) { (void)driver; (void)flags; SDL_EnableUNICODE(1); (void)SDL_GetKeyState (&num_keys); kbdstate = (int *)HMalloc (sizeof (int) * (num_keys + 1)); #ifdef HAVE_JOYSTICK initJoystick (); #endif /* HAVE_JOYSTICK */ in_character_mode = FALSE; resetKeyboardState (); /* Prepare the Virtual Controller system. */ VControl_Init (); initKeyConfig (); VControl_ResetInput (); InputInitialized = TRUE; return 0; }
void InitEmptyCeosRecord(CeosRecord_t *record, int32 sequence, CeosTypeCode_t typecode, int32 length) { if(record) { if((record->Buffer = HMalloc(length)) == NULL) { return; } /* First we zero fill the buffer */ memset(record->Buffer,0,length); /* Setup values inside the CeosRecord_t header */ record->Sequence = sequence; record->Flavour = 0; record->FileId = 0; record->TypeCode = typecode; record->Subsequence = 0; record->Length = length; /* Now we fill in the buffer portion as well */ NativeToCeos( record->Buffer+__SEQUENCE_OFF, &(record->Sequence), sizeof(record->Sequence), sizeof( record->Sequence ) ); memcpy(record->Buffer+__TYPE_OFF, &( record->TypeCode.Int32Code ), sizeof( record->TypeCode.Int32Code ) ); NativeToCeos( record->Buffer+__LENGTH_OFF, &length, sizeof( length ), sizeof( length ) ); } }
TFB_VideoDecoder* VideoDecoder_Load (uio_DirHandle *dir, const char *filename) { const char* pext; TFB_RegVideoDecoder* info; TFB_VideoDecoder* decoder; if (!vd_inited) return NULL; pext = strrchr (filename, '.'); if (!pext) { log_add (log_Warning, "VideoDecoder_Load: Unknown file type"); return NULL; } ++pext; for (info = vd_decoders; info->used && (!info->ext || strcmp (info->ext, pext) != 0); ++info) ; if (!info->ext) { log_add (log_Warning, "VideoDecoder_Load: Unsupported file type"); return NULL; } decoder = (TFB_VideoDecoder*) HCalloc (info->funcs->GetStructSize ()); decoder->funcs = info->funcs; if (!decoder->funcs->Init (decoder, &vd_vidfmt)) { log_add (log_Warning, "VideoDecoder_Load: " "Cannot init '%s' decoder, code %d", decoder->funcs->GetName (), decoder->funcs->GetError (decoder)); HFree (decoder); return NULL; } decoder->dir = dir; decoder->filename = (char *) HMalloc (strlen (filename) + 1); strcpy (decoder->filename, filename); decoder->error = VIDEODECODER_OK; if (!decoder->funcs->Open (decoder, dir, filename)) { log_add (log_Warning, "VideoDecoder_Load: " "'%s' decoder did not load %s, code %d", decoder->funcs->GetName (), filename, decoder->funcs->GetError (decoder)); VideoDecoder_Free (decoder); return NULL; } return decoder; }
void * HCalloc (int size) { void *p; p = HMalloc (size); memset (p, 0, size); return (p); }
static void GetScriptResData (const char *pathName, RESOURCE_DATA *resdata) { // We don't actually load the data here. We determine the file name, and // load the data when we need it, directly onto the Lua stack. size_t pathNameLen = strlen (pathName); resdata->ptr = HMalloc (pathNameLen + 1); if (resdata->ptr == NULL) return; memcpy (resdata->ptr, pathName, pathNameLen + 1); }
static char* cdp_MakeContextName (const char* ctx, const char* name) { int namelen; char* id_name; namelen = strlen(ctx) + strlen(name) + 2; id_name = HMalloc (namelen); strcpy(id_name, ctx); strcat(id_name, "."); strcat(id_name, name); return id_name; }
MREADER* moda_new_uioReader (uio_Stream* fp) { MUIOREADER* reader = (MUIOREADER*) HMalloc (sizeof(MUIOREADER)); if (reader) { reader->core.Eof = &moda_uioReader_Eof; reader->core.Read = &moda_uioReader_Read; reader->core.Get = &moda_uioReader_Get; reader->core.Seek = &moda_uioReader_Seek; reader->core.Tell = &moda_uioReader_Tell; reader->file = fp; } return (MREADER*)reader; }
static char *ExtractString( CeosRecord_t *record, unsigned int offset, unsigned int length, char *string ) { char format[12]; if(string == NULL) { string = HMalloc( length + 1 ); } sprintf( format, "A%u", length ); GetCeosField( record, offset, format, string ); return string; }
static SDL_RWops * sdluio_makeRWops (uio_Stream *stream) { SDL_RWops *result; result = HMalloc (sizeof (SDL_RWops)); #if 0 *(struct SDL_RWops *) result = sdluio_templateRWops; // structure assignment #endif result->seek = sdluio_seek; result->read = sdluio_read; result->write = sdluio_write; result->close = sdluio_close; result->hidden.unknown.data1 = stream; return result; }
void LoadTeamList (MELEE_STATE *pMS) { COUNT i; DestroyDirEntryTable (ReleaseDirEntryTable (pMS->load.dirEntries)); pMS->load.dirEntries = CaptureDirEntryTable ( LoadDirEntryTable (meleeDir, "", ".mle", match_MATCH_SUFFIX)); if (pMS->load.entryIndices != NULL) HFree (pMS->load.entryIndices); pMS->load.numIndices = GetDirEntryTableCount (pMS->load.dirEntries); pMS->load.entryIndices = HMalloc (pMS->load.numIndices * sizeof pMS->load.entryIndices[0]); for (i = 0; i < pMS->load.numIndices; i++) pMS->load.entryIndices[i] = i; }
GAME_STATE_FILE * OpenStateFile (int stateFile, const char *mode) { GAME_STATE_FILE *fp; if (stateFile < 0 || stateFile >= NUM_STATE_FILES) return NULL; fp = &state_files[stateFile]; fp->open_count++; if (fp->open_count > 1) log_add (log_Warning, "WARNING: " "State file %s open count is %d after open()", fp->symname, fp->open_count); if (!fp->data) { fp->data = HMalloc (fp->size_hint); if (!fp->data) return NULL; fp->size = fp->size_hint; } // we allow reading and writing for any open mode // but the mode determines what happens to the file contents if (mode[0] == 'w') { // blow the file away fp->used = 0; #ifdef DEBUG // paint buffer for tracking writes memset (fp->data, 0xCC, fp->size); #endif } else if (mode[0] == 'r') { // nothing } else { log_add (log_Warning, "WARNING: " "State file %s opened with unsupported mode '%s'", fp->symname, mode); } fp->ptr = 0; return fp; }
static cdp_EventBind* cdp_AllocEventBinds (cdp_EventBind* binds, uint32 ccur, uint32 cnew) { cdp_EventBind* newbinds; uint32 newsize; newsize = cnew * sizeof (cdp_EventBind); if (binds) newbinds = HRealloc (binds, newsize); else newbinds = HMalloc (newsize); if (cnew > ccur) memset (newbinds + ccur, 0, (cnew - ccur) * sizeof (cdp_EventBind)); return newbinds; }
static void set_strtab_entry (STRING_TABLE_DESC *strtab, int index, const char *value, int len) { STRING str = &strtab->strings[index]; if (str->data) { HFree (str->data); str->data = NULL; str->length = 0; } if (len) { str->data = HMalloc (len); str->length = len; memcpy (str->data, value, len); } }
static keypool * allocate_key_chunk (void) { keypool *x = HMalloc (sizeof (keypool)); if (x) { int i; x->remaining = POOL_CHUNK_SIZE; x->next = NULL; for (i = 0; i < POOL_CHUNK_SIZE; i++) { x->pool[i].target = NULL; x->pool[i].next = NULL; x->pool[i].parent = x; } } return x; }
static void processFontChar (TFB_Char* CharPtr, TFB_Canvas canvas) { BYTE* newdata; size_t dpitch; TFB_DrawCanvas_GetExtent (canvas, &CharPtr->extent); // Currently, each font char has its own separate data // but that can change to common mem area dpitch = CharPtr->extent.width; newdata = HMalloc (dpitch * CharPtr->extent.height * sizeof (BYTE)); TFB_DrawCanvas_GetFontCharData (canvas, newdata, dpitch); CharPtr->data = newdata; CharPtr->pitch = dpitch; CharPtr->disp.width = CharPtr->extent.width + 1; CharPtr->disp.height = CharPtr->extent.height + 1; // XXX: why the +1? // I brought it into this function from the only calling // function, but I don't know why it was there in the first // place. // XXX: the +1 appears to be for character and line spacing // text_blt just adds the frame width to move to the next char { // This tunes the font positioning to be about what it should // TODO: prolly needs a little tweaking still int tune_amount = 0; if (CharPtr->extent.height == 8) tune_amount = -1; else if (CharPtr->extent.height == 9) tune_amount = -2; else if (CharPtr->extent.height > 9) tune_amount = -3; CharPtr->HotSpot = MAKE_HOT_SPOT (0, CharPtr->extent.height + tune_amount); } }
TFB_Image* TFB_DrawImage_CreateForScreen (int w, int h, BOOLEAN withalpha) { TFB_Image* img = HMalloc (sizeof (TFB_Image)); img->mutex = CreateMutex ("image lock", SYNC_CLASS_VIDEO); img->ScaledImg = NULL; img->MipmapImg = NULL; img->FilledImg = NULL; img->colormap_index = -1; img->colormap_version = 0; img->NormalHs = NullHs; img->MipmapHs = NullHs; img->last_scale_hs = NullHs; img->last_scale_type = -1; img->last_scale = 0; img->extent.width = w; img->extent.height = h; img->NormalImg = TFB_DrawCanvas_New_ForScreen (w, h, withalpha); return img; }
static FlashContext * Flash_create (CONTEXT gfxContext) { FlashContext *context = HMalloc (sizeof (FlashContext)); context->gfxContext = gfxContext; context->original = 0; context->startNumer = 0; context->endNumer = 1; context->denom = 1; context->fadeInTime = Flash_DEFAULT_FADE_IN_TIME; context->onTime = Flash_DEFAULT_ON_TIME; context->fadeOutTime = Flash_DEFAULT_FADE_OUT_TIME; context->offTime = Flash_DEFAULT_OFF_TIME; context->frameTime = 0; context->state = FlashState_off; context->lastStateTime = 0; context->lastFrameTime = 0; context->started = false; context->paused = false; context->cache = 0; context->cacheSize = Flash_DEFAULT_CACHE_SIZE; context->lastFrameIndex = (COUNT) -1; // TODO: Delete the context somewhere if (!workGfxContext) workGfxContext = CreateContext ("Flash.workGfxContext"); return context; }