// for GS_ARENA, count must be 4, 8, 16 or 20 void *__gs_mempool_alloc(unsigned int arena_id, unsigned int count) { gs_arena_t *arena = &gs_mempool[arena_id]; gs_memblock_t *memblk = arena->lastblock; if (memblk == NULL) { #ifdef TARG_IA64 // On IA64, the sizeof(gspin_t) is 32 GS_ASSERT(sizeof(gspin_t) == 32, "struct gspin size has changed."); #else GS_ASSERT(sizeof(gspin_t) == 20, "struct gspin size has changed."); #endif memblk = gs_new_memblock(0); arena->firstblock = arena->lastblock = memblk; arena->current_index = 0; } else if ((arena->current_index + count - 1) >= ((memblk->block_id + 1) << GS_BLOCK_IDX_SHIFT_AMT)) { memblk = gs_new_memblock(memblk->block_id + 1); arena->lastblock->next = memblk; arena->lastblock = memblk; if (count > 1) // this is needed to gaurantee locations to be contiguous arena->current_index = memblk->block_id * GS_MEMBLOCK_SIZE; } gs_void_t *p = &memblk->mem[arena->current_index & GS_OFST_IN_BLK_MASK]; arena->current_index += count; return p; }
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // UDP Layer must be initialized // theIp and thePort cannot be 0 (Zero) // Based on an IP and port, the function will return the amount of free space // of a peer's buffer. int gsUdpEngineGetPeerOutBufferFreeSpace(unsigned int theIp, unsigned short thePort) { GSUdpEngineObject *aUdp = gsUdpEngineGetEngine(); GSUdpRemotePeer aRemotePeer, *aRemotePeerFound; int index; GS_ASSERT(aUdp->mInitialized); GS_ASSERT(theIp); GS_ASSERT(thePort); if (!aUdp->mInitialized) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Debug, "[Udp Engine] Engine not initialized\n"); return 0; } aRemotePeer.mAddr = theIp; aRemotePeer.mPort = thePort; index = ArraySearch(aUdp->mRemotePeers, &aRemotePeer, gsUdpRemotePeerCompare, 0, 0); if (index != NOT_FOUND) { aRemotePeerFound = (GSUdpRemotePeer *)ArrayNth(aUdp->mRemotePeers, index); return gt2GetOutgoingBufferFreeSpace(aRemotePeerFound->mConnection); } return 0; }
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // UDP Layer must be initialized // Used obtain the peer's state // theIp and thePort cannot be 0 (Zero) GSUdpErrorCode gsUdpEngineGetPeerState(unsigned int theIp, unsigned short thePort, GSUdpPeerState *thePeerState) { GSUdpEngineObject *aUdp = gsUdpEngineGetEngine(); GSUdpRemotePeer aPeer, *aPeerFound; int index; GS_ASSERT(aUdp->mInitialized); GS_ASSERT(theIp); GS_ASSERT(thePort); GS_ASSERT(thePeerState != NULL); if (!aUdp->mInitialized) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_State, GSIDebugLevel_Debug, "[Udp Engine] Engine not initialized\n"); *thePeerState = GS_UDP_PEER_CLOSED; return GS_UDP_NOT_INITIALIZED; } aPeer.mAddr = theIp; aPeer.mPort = thePort; index = ArraySearch(aUdp->mRemotePeers, &aPeer, gsUdpRemotePeerCompare, 0, 0); if (index == NOT_FOUND) { *thePeerState = GS_UDP_PEER_CLOSED; return GS_UDP_NO_ERROR; } aPeerFound = (GSUdpRemotePeer *)ArrayNth(aUdp->mRemotePeers, index); *thePeerState = (GSUdpPeerState)gt2GetConnectionState(aPeerFound->mConnection); return GS_UDP_NO_ERROR; }
gsi_bool wsLoginCertReadXML(GSLoginCertificate * cert, GSXmlStreamReader reader) { char hexstr[GS_CRYPT_RSA_BYTE_SIZE*2 +1]; // temp storage for key hex strings int hexlen; GS_ASSERT(cert != NULL); GS_ASSERT(reader != NULL); if (gsi_is_false(gsXmlReadChildAsInt (reader, "length", (int*)&cert->mLength)) || gsi_is_false(gsXmlReadChildAsInt (reader, "version", (int*)&cert->mVersion)) || gsi_is_false(gsXmlReadChildAsInt (reader, "partnercode",(int*)&cert->mPartnerCode)) || gsi_is_false(gsXmlReadChildAsInt (reader, "namespaceid",(int*)&cert->mNamespaceId)) || gsi_is_false(gsXmlReadChildAsInt (reader, "userid", (int*)&cert->mUserId)) || gsi_is_false(gsXmlReadChildAsInt (reader, "profileid", (int*)&cert->mProfileId)) || gsi_is_false(gsXmlReadChildAsInt (reader, "expiretime", (int*)&cert->mExpireTime)) || gsi_is_false(gsXmlReadChildAsTStringNT (reader, "profilenick", cert->mProfileNick, WS_LOGIN_NICK_LEN)) || gsi_is_false(gsXmlReadChildAsTStringNT (reader, "uniquenick", cert->mUniqueNick, WS_LOGIN_UNIQUENICK_LEN)) || gsi_is_false(gsXmlReadChildAsTStringNT (reader, "cdkeyhash", cert->mCdKeyHash, WS_LOGIN_KEYHASH_LEN)) || gsi_is_false(gsXmlReadChildAsStringNT (reader, "peerkeymodulus", hexstr, GS_CRYPT_RSA_BYTE_SIZE*2 +1)) || gsi_is_false(gsLargeIntSetFromHexString(&cert->mPeerPublicKey.modulus, hexstr)) || gsi_is_false(gsXmlReadChildAsStringNT (reader, "peerkeyexponent", hexstr, GS_CRYPT_RSA_BYTE_SIZE*2 +1)) || gsi_is_false(gsLargeIntSetFromHexString(&cert->mPeerPublicKey.exponent, hexstr)) || gsi_is_false(gsXmlReadChildAsHexBinary(reader, "serverdata", cert->mServerData, WS_LOGIN_SERVERDATA_LEN, &hexlen)) || gsi_is_false(gsXmlReadChildAsHexBinary(reader, "signature", cert->mSignature, WS_LOGIN_SIGNATURE_LEN, &hexlen)) ) { return gsi_false; } return gsi_true; }
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // UDP Layer must be initialized // When a message handler is done or shutting down, the message handler should remove // itself from the UDP Layer // The header cannot be empty GSUdpErrorCode gsUdpEngineRemoveMsgHandler(char theHeader[GS_UDP_MSG_HEADER_LEN]) { GSUdpEngineObject *aUdp = gsUdpEngineGetEngine(); GSUdpMsgHandler aHandler; int index; GS_ASSERT(aUdp->mInitialized); GS_ASSERT(theHeader); if (!aUdp->mInitialized) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Debug, "[Udp Engine] Engine not initialized\n"); return GS_UDP_NETWORK_ERROR; } if (!theHeader || !theHeader[0]) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Debug, "[Udp Engine] invalid or empty header\n"); return GS_UDP_PARAMETER_ERROR; } memcpy(aHandler.mHeader, theHeader, GS_UDP_MSG_HEADER_LEN); index = ArraySearch(aUdp->mMsgHandlers, &aHandler, gsUdpMsgHandlerCompare2, 0, 0); if (index != NOT_FOUND) { ArrayDeleteAt(aUdp->mMsgHandlers, index); } return GS_UDP_NO_ERROR; }
bool add_definition(const char* original, const char* replacement) { int cmp = strcmp(original, replacement); GS_ASSERT(original[0] != '\0'); GS_ASSERT(replacement[0] != '\0'); GS_ASSERT(this->size < this->max); GS_ASSERT(cmp != 0); if (original[0] == '\0') return false; if (replacement[0] == '\0') return false; if (this->size >= this->max) return false; if (cmp == 0) return false; // make sure the original name is not duplicated for (size_t i=0; i<this->size; i++) { size_t index = this->get_index(i); int cmp = strcmp(original, &this->originals[index]); GS_ASSERT(cmp != 0); if (cmp == 0) return false; } size_t index = this->get_index(this->size); strncpy(&this->originals[index], original, this->name_max); this->originals[index + this->name_max] = '\0'; strncpy(&this->replacements[index], replacement, this->name_max); this->replacements[index + this->name_max] = '\0'; this->size++; return true; }
gsi_bool wsLoginCertWriteXML(const GSLoginCertificate * cert, const char * aNamespace, GSXmlStreamWriter writer) { GS_ASSERT(cert != NULL); GS_ASSERT(writer != NULL); if (gsi_is_false(gsXmlWriteIntElement(writer, aNamespace, "length", cert->mLength)) || gsi_is_false(gsXmlWriteIntElement(writer, aNamespace, "version", cert->mVersion)) || gsi_is_false(gsXmlWriteIntElement(writer, aNamespace, "partnercode", cert->mPartnerCode)) || gsi_is_false(gsXmlWriteIntElement(writer, aNamespace, "namespaceid", cert->mNamespaceId)) || gsi_is_false(gsXmlWriteIntElement(writer, aNamespace, "userid", cert->mUserId)) || gsi_is_false(gsXmlWriteIntElement(writer, aNamespace, "profileid", cert->mProfileId)) || gsi_is_false(gsXmlWriteIntElement(writer, aNamespace, "expiretime", cert->mExpireTime)) || gsi_is_false(gsXmlWriteAsciiStringElement(writer, aNamespace, "profilenick", cert->mProfileNick))|| gsi_is_false(gsXmlWriteAsciiStringElement(writer, aNamespace, "uniquenick", cert->mUniqueNick)) || gsi_is_false(gsXmlWriteAsciiStringElement(writer, aNamespace, "cdkeyhash", cert->mCdKeyHash)) || gsi_is_false(gsXmlWriteLargeIntElement(writer, aNamespace, "peerkeymodulus", &cert->mPeerPublicKey.modulus)) || gsi_is_false(gsXmlWriteLargeIntElement(writer, aNamespace, "peerkeyexponent", &cert->mPeerPublicKey.exponent)) || gsi_is_false(gsXmlWriteHexBinaryElement(writer, aNamespace, "serverdata", cert->mServerData, WS_LOGIN_SERVERDATA_LEN)) || gsi_is_false(gsXmlWriteHexBinaryElement(writer, aNamespace, "signature", cert->mSignature, WS_LOGIN_SIGNATURE_LEN)) ) { //gsLargeIntReverseBytes(&cert->mPeerPublicKey.modulus); //gsLargeIntReverseBytes(&cert->mPeerPublicKey.exponent); return gsi_false; } //gsLargeIntReverseBytes(&cert->mPeerPublicKey.modulus); //gsLargeIntReverseBytes(&cert->mPeerPublicKey.exponent); return gsi_true; }
SCResult sciInterfaceCreate(SCInterface** theInterfaceOut) { #ifdef GSI_SC_STATIC_MEM static SCInterface gStaticInterface; #endif GS_ASSERT(theInterfaceOut != NULL); // Check to see if the availability check has been performed and if it has // set the service URL prepended with the gamename if (__GSIACResult == GSIACAvailable) { if (scServiceURL[0] == '\0') snprintf(scServiceURL, SC_SERVICE_MAX_URL_LEN, SC_SERVICE_URL_FORMAT, __GSIACGamename); } else return SCResult_NO_AVAILABILITY_CHECK; #ifdef GSI_SC_STATIC_MEM *theInterfaceOut = &gStaticInterface; #else *theInterfaceOut = (SCInterface*)gsimalloc(sizeof(SCInterface)); if (*theInterfaceOut == NULL) { return SCResult_OUT_OF_MEMORY; } #endif GS_ASSERT(*theInterfaceOut != NULL); memset(*theInterfaceOut, 0, sizeof(SCInterface)); return SCResult_NO_ERROR; }
size_t parse_block(bool (*process_token) (const char*, const char*, Data*), const char* terminator, const char* str, Data* data) { data->reset(); data->valid = false; const size_t LONGEST_LINE = 0x7F; static char buf[LONGEST_LINE+1] = {'\0'}; size_t i = 0; while (1) { char c = '\0'; size_t n = 0; while ((c = str[i++]) != '\0' && c != '\n' && n < LONGEST_LINE) buf[n++] = c; buf[n] = '\0'; GS_ASSERT(c == '\n'); if (c != '\n') return i; if (strcmp(buf, terminator) == 0) break; GS_ASSERT(n > TAG_LENGTH + TAG_DELIMITER_LENGTH); if (n <= TAG_LENGTH + TAG_DELIMITER_LENGTH) return i; GS_ASSERT(buf[TAG_LENGTH] == TAG_DELIMITER[0]); if (buf[TAG_LENGTH] != TAG_DELIMITER[0]) return i; buf[TAG_LENGTH] = '\0'; const char* key = &buf[0]; const char* token = &buf[TAG_LENGTH+1]; if (!process_token(key, token, data)) return i; } data->valid = true; return i; }
/* ArrayGrow * Reallocates the array to a new size, incresed by growby */ static void ArrayGrow(DArray array) { GS_ASSERT(array->elemsize) // sanity check -mj Oct 31st array->capacity += array->growby; array->list = gsirealloc(array->list, (size_t) array->capacity * array->elemsize); GS_ASSERT(array->list); }
void map_chunk_uncompressed_StoC::handle(char* buff, size_t byte_num) { //printf("map_chunk: alias= %d for %d %d \n", chunk_alias, chunk_index%MAP_CHUNK_XDIM, chunk_index /MAP_CHUNK_XDIM); //printf("byte_size= %d \n", byte_size); #if MAP_NET_DEBUG printf("map chunk is %d bytes \n", byte_size); #endif GS_ASSERT(client_chunk_alias_list[chunk_alias] == -1); client_chunk_alias_list[chunk_alias] = chunk_index; int cx = chunk_index % MAP_CHUNK_XDIM; int cy = chunk_index / MAP_CHUNK_XDIM; GS_ASSERT(main_map->chunk[chunk_index] == NULL); main_map->load_chunk(cx, cy); class MapChunk* m = main_map->chunk[chunk_index]; /* This is evil, dont do this */ memcpy((char *) m->e, buff, byte_num); m->refresh_height_cache(); //refesh height cache after memcpy main_map->chunk_received(cx,cy); }
// NOTE: use this function only when in a UDP layer callback GPIPeer * gpiGetPeerByAddr(const GPConnection *connection, unsigned int ip, unsigned short port) { GPIConnection * iconnection = (GPIConnection*)*connection; GPIPeer * pcurr; GS_ASSERT(ip); GS_ASSERT(port); if (!ip && !port) return NULL; // Go through the list of peers. //////////////////////////////// for(pcurr = iconnection->peerList ; pcurr != NULL ; pcurr = pcurr->pnext) { // Check for a match. ///////////////////// if(pcurr->ip == ip && pcurr->port == port) { // Got it. ////////// return pcurr; } } return NULL; }
// gpiPeerAddOp notes: // Assumes non-null inputs! // The queue should be empty when the first element is added. // Any new element added will be added to the end of the queue. void gpiPeerAddOp(GPIPeer *peer, GPIPeerOp *operation) { GS_ASSERT(peer); GS_ASSERT(operation); if (!peer || !operation) { gsDebugFormat(GSIDebugCat_GP, GSIDebugType_Misc, GSIDebugLevel_WarmError, "Peer operation not added"); return; } // Three cases can occur: // The list is empty - set all pointers to the new node // The list has only one element - set the first element's next to the new // and set the last element to the new // The list has more than one element - add the new element to the end of // the queue if (peer->peerOpQueue.opList == NULL) { peer->peerOpQueue.first = operation; peer->peerOpQueue.last = operation; peer->peerOpQueue.opList = operation; } else if (peer->peerOpQueue.first == peer->peerOpQueue.last) { peer->peerOpQueue.first->next = operation; peer->peerOpQueue.last = operation; } else { peer->peerOpQueue.last->next = operation; peer->peerOpQueue.last = operation; } gsDebugFormat(GSIDebugCat_GP, GSIDebugType_Misc, GSIDebugLevel_Notice, "Peer Operation Added"); }
GS_VOID CPokeMiniEmulatorDlg::OnRomOpen() { OnRomClose(); { CFileDialog fileDialog(TRUE, _T("*.min"), NULL, OFN_ALLOWMULTISELECT|OFN_HIDEREADONLY|OFN_EXPLORER, _T("pokemon mini rom(*.min)|*.min")); if (IDOK == fileDialog.DoModal()) { CString fileName = fileDialog.GetPathName(); FILE *pFile = _wfopen(fileName, L"rb"); fseek(pFile, 0, SEEK_END); m_romSize = ftell(pFile); m_pRomData = GS_MALLOCZ_OBJ_N(GS_BYTE, m_romSize); fseek(pFile, 0, SEEK_SET); fread(m_pRomData, 1, m_romSize, pFile); fclose(pFile); m_pSaveData = GS_MALLOCZ_OBJ_N(GS_BYTE, m_pSystem->SaveSize()); } } if (m_pSystem->Initialize(m_pRomData, m_romSize, m_pSaveData)) { HRESULT hr = S_OK; hr = m_pDirectSoundBuffer->SetCurrentPosition(0); GS_ASSERT(SUCCEEDED(hr)); hr = m_pDirectSoundBuffer->Play(0, 0, DSBPLAY_LOOPING); GS_ASSERT(SUCCEEDED(hr)); m_state = EMU_RUN; m_emuThread = CreateThread(NULL, 0, EmuThread, this, 0, &m_emuThreadID); } }
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // UDP Layer must be initialized // theIp and thePort cannot be 0 (Zero) // Rejects a Peer's request for communication // Should only be used by App GSUdpErrorCode gsUdpEngineRejectPeer(unsigned int theIp, unsigned short thePort) { GSUdpRemotePeer aRemotePeer; GSUdpEngineObject *aUdp = gsUdpEngineGetEngine(); int index; GS_ASSERT(aUdp->mInitialized); GS_ASSERT(theIp); GS_ASSERT(thePort); if (!aUdp->mInitialized) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Debug, "[Udp Engine] Engine not initialized\n"); return GS_UDP_NETWORK_ERROR; } if (theIp == 0 || thePort == 0) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Debug, "[Udp Engine] Invalid parameter(s), check ip, port\n"); return GS_UDP_PARAMETER_ERROR; } // Find the connection to reject in our array of peers aRemotePeer.mAddr = theIp; aRemotePeer.mPort = thePort; index = ArraySearch(aUdp->mRemotePeers, &aRemotePeer, gsUdpRemotePeerCompare, 0, 0); if (index != NOT_FOUND) { GSUdpRemotePeer *aPeerFound = (GSUdpRemotePeer *)ArrayNth(aUdp->mRemotePeers, index); gt2Reject(aPeerFound->mConnection, NULL, 0); ArrayDeleteAt(aUdp->mRemotePeers, index); } return GS_UDP_NO_ERROR; }
/* SetElement * Sets the element at pos to the contents of elem */ static void SetElement(DArray array, const void *elem, int pos) { GS_ASSERT(array) // safety check -mj Oct 31st GS_ASSERT(elem) GS_ASSERT(array->elemsize) memcpy(ArrayNth(array,pos), elem, (size_t)array->elemsize); }
static void init_equipment_texture() { GLuint min_filter = GL_LINEAR; GLuint mag_filter = GL_NEAREST; int ret = create_texture_from_file(MEDIA_PATH "sprites/container/equipment48.png", &EquipmentTexture, min_filter, mag_filter); GS_ASSERT(ret == 0); GS_ASSERT(EquipmentTexture != 0); }
static void init_crusher_texture() { GLuint min_filter = GL_LINEAR; GLuint mag_filter = GL_NEAREST; int ret = create_texture_from_file(MEDIA_PATH "sprites/container/crusher48.png", &CrusherTexture, min_filter, mag_filter); GS_ASSERT(ret == 0); GS_ASSERT(CrusherTexture != 0); }
static void init_storage_block_texture() { GLuint min_filter = GL_LINEAR; GLuint mag_filter = GL_NEAREST; int ret = create_texture_from_file(MEDIA_PATH "sprites/container/storage_block48.png", &StorageBlockTexture, min_filter, mag_filter); GS_ASSERT(ret == 0); GS_ASSERT(StorageBlockTexture != 0); }
bool save_active_names(const Property* properties, size_t count, size_t name_len, const char* filename) { bool worked = false; const char tmp[] = ".tmp"; char* tmp_filename = (char*)malloc((strlen(filename) + sizeof(tmp)) * sizeof(char)); sprintf(tmp_filename, "%s%s", filename, tmp); const char bak[] = ".bak"; char* bak_filename = (char*)malloc((strlen(filename) + sizeof(bak)) * sizeof(char)); sprintf(bak_filename, "%s%s", filename, bak); char* buf = (char*)malloc((name_len+2) * sizeof(char)); FILE* f = fopen(tmp_filename, "w"); GS_ASSERT(f != NULL); if (f == NULL) goto error; for (size_t i=0; i<count; i++) { if (!properties[i].loaded) continue; size_t len = strlen(properties[i].name); GS_ASSERT(len > 0 && len <= name_len); if (len <= 0 || len > name_len) goto error; strncpy(buf, properties[i].name, len); buf[len] = '\n'; buf[len+1] = '\0'; size_t wrote = fwrite(buf, sizeof(char), len+1, f); GS_ASSERT(wrote == len + 1); if (wrote != len + 1) goto error; } worked = true; error: // ERROR LABEL if (f != NULL) { worked = (fclose(f) == 0); GS_ASSERT(worked); } if (worked) { worked = save_tmp_file(filename, tmp_filename, bak_filename); GS_ASSERT(worked); } free(tmp_filename); free(bak_filename); free(buf); return worked; }
void set_cube_palette_texture(CubeType id, int side, int tex_id) { GS_ASSERT_ABORT(cube_texture_palette_debug[cube_texture_palette_index] == 1); cube_texture_palette[6*cube_texture_palette_index + side] = tex_id; GS_ASSERT(cube_texture_palette_index <= cube_texture_palette_lookup[id] + cube_texture_palette_lookup_max[id]); GS_ASSERT(cube_texture_palette_index >= cube_texture_palette_lookup[id]); }
void set_periodic(int duration, int period) { GS_ASSERT(this->duration == -1 && this->period == -1); GS_ASSERT(duration >= 0 && period >= 0); GS_ASSERT(duration >= period); this->duration = duration; this->period = period; this->event_type = MODIFIER_EVENT_PERIODIC; }
void VoxelRenderListManager::unregister_voxel_volume(class VoxelVolume* vv) { GS_ASSERT(this->max > 0); GS_ASSERT(this->lists != NULL); // unregister from correct list int id = vv->voxel_render_list_id; if (id < 0 || id >= this->max) return; this->lists[id].unregister_voxel_volume(vv); }
GPResult gpiPeerAddMessage( GPConnection * connection, GPIPeer * peer, int type, const char * message ) { GPIMessage gpiMessage; int len; GS_ASSERT(peer != NULL); GS_ASSERT(message != NULL); if (peer == NULL) return GP_NETWORK_ERROR; if (message == NULL) return GP_NETWORK_ERROR; // Get the length. ////////////////// len = (int)strlen(message); // Clear the message. ///////////////////// memset(&gpiMessage, 0, sizeof(GPIMessage)); // Copy the type. ///////////////// gpiMessage.type = type; // Copy the header to the buffer. ///////////////////////////////// CHECK_RESULT(gpiAppendStringToBuffer(connection, &gpiMessage.buffer, "\\m\\")); CHECK_RESULT(gpiAppendIntToBuffer(connection, &gpiMessage.buffer, type)); CHECK_RESULT(gpiAppendStringToBuffer(connection, &gpiMessage.buffer, "\\len\\")); CHECK_RESULT(gpiAppendIntToBuffer(connection, &gpiMessage.buffer, len)); CHECK_RESULT(gpiAppendStringToBuffer(connection, &gpiMessage.buffer, "\\msg\\\n")); // Copy the message to the buffer. ////////////////////////////////// gpiMessage.start = gpiMessage.buffer.len; CHECK_RESULT(gpiAppendStringToBufferLen(connection, &gpiMessage.buffer, message, len)); CHECK_RESULT(gpiAppendCharToBuffer(connection, &gpiMessage.buffer, '\0')); // Add it to the list. ////////////////////// ArrayAppend(peer->messages, &gpiMessage); // Reset the timeout. ///////////////////// peer->timeout = (time(NULL) + GPI_PEER_TIMEOUT); return GP_NO_ERROR; }
GHTTPBool ghttpPostAddXml ( GHTTPPost post, GSXmlStreamWriter soap ) { GS_ASSERT(post != NULL); GS_ASSERT(soap != NULL); return ghiPostAddXml(post, soap); }
bool save(const char* filename) { bool worked = false; const char line_ending[] = "\n"; const char tmp[] = ".tmp"; char* tmp_filename = (char*)malloc((strlen(filename) + sizeof(tmp)) * sizeof(char)); sprintf(tmp_filename, "%s%s", filename, tmp); const char bak[] = ".bak"; char* bak_filename = (char*)malloc((strlen(filename) + sizeof(bak)) * sizeof(char)); sprintf(bak_filename, "%s%s", filename, bak); FILE* f = fopen(tmp_filename, "w"); GS_ASSERT(f != NULL); if (f == NULL) goto error; for (size_t i=0; i<this->size; i++) { size_t index = this->get_index(i); size_t len = strlen(&this->originals[index]); size_t wrote = fwrite(&this->originals[index], sizeof(char), len, f); GS_ASSERT(wrote == len); if (wrote != len) goto error; wrote = fwrite(line_ending, sizeof(char), sizeof(line_ending)-1, f); GS_ASSERT(wrote == sizeof(line_ending)-1); if (wrote != sizeof(line_ending)-1) goto error; } worked = true; error: // ERROR LABEL if (f != NULL) { worked = (fclose(f) == 0); GS_ASSERT(worked); } if (worked) { worked = save_tmp_file(filename, tmp_filename, bak_filename); GS_ASSERT(worked); } free(tmp_filename); free(bak_filename); return worked; }
void sciInterfaceSetConnectionId(SCInterface * theInterface, const char * theConnectionId) { GS_ASSERT(theInterface != NULL); if (theConnectionId == NULL) theInterface->mConnectionId[0] = '\0'; else { GS_ASSERT(strlen(theConnectionId) < sizeof(theInterface->mConnectionId)); strcpy((char *)theInterface->mConnectionId, theConnectionId); } }
void VoxelRenderList::update_vertex_buffer_object() { VoxelVolume* vv = NULL; struct VBOmeta* _vbo = &vbo_wrapper[0]; int v_num = 0; int volumes_updated = 0; for (int i=0; i < VOXEL_RENDER_LIST_SIZE; i++) { if (this->render_list[i] == NULL) continue; vv = this->render_list[i]; if (vv->needs_vbo_update) { vv->needs_vbo_update = false; volumes_updated++; vv->update_vertex_list(); } v_num += vv->vvl.vnum; } _vbo->vnum = v_num; if (v_num == 0) return; if (!this->needs_update && volumes_updated == 0) return; //return if nothing to update this->needs_update = false; if (v_num >= _vbo->max_size) { while (v_num >= _vbo->max_size) _vbo->max_size *= 2; //double max size until its large enough and realloc _vbo->vertex_list = (VoxelVertex*)realloc(_vbo->vertex_list, _vbo->max_size*sizeof(VoxelVertex)); } int index = 0; // continue counting indices, but realigning changed data for (int i=0; i < VOXEL_RENDER_LIST_SIZE; i++) { if (this->render_list[i] == NULL) continue; vv = this->render_list[i]; GS_ASSERT(vv->vvl.vnum != 0); GS_ASSERT(vv->vvl.vertex_list != 0) memcpy(&_vbo->vertex_list[index], vv->vvl.vertex_list, vv->vvl.vnum*sizeof(VoxelVertex)); vv->vvl.voff = index; index += vv->vvl.vnum; } GS_ASSERT(index == v_num); if (_vbo->id == 0) glGenBuffers(1, &_vbo->id); glBindBuffer(GL_ARRAY_BUFFER, _vbo->id); glBufferData(GL_ARRAY_BUFFER, index*sizeof(VoxelVertex), NULL, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, index*sizeof(VoxelVertex), _vbo->vertex_list, GL_STATIC_DRAW); }
SCResult SC_CALL sciReportAddFloatValue(SCIReport * theReport, gsi_u16 theKeyId, float theValue) { SCIReportHeader * aHeader = (SCIReportHeader*)theReport->mBuffer.mData; int writtenLen = 0; gsi_i16 theKeyType = SCIKeyType_FLOAT; // calculate length of data to be written writtenLen += sizeof(gsi_u16) + sizeof(gsi_u16); // 2 byte key ID, 2 byte key type; writtenLen += sizeof(float); // stored in stream as a 4 byte char array // Check room in buffer GS_ASSERT((theReport->mBuffer.mPos + writtenLen) < theReport->mBuffer.mCapacity); // Update count and length markers if (theReport->mReportState == SCIReportState_GLOBALDATA) { aHeader->mGameKeyCount++; aHeader->mGameSectionLength += writtenLen; } else if (theReport->mReportState == SCIReportState_PLAYERDATA) { GS_ASSERT(theReport->mCurEntityStartPos != -1); aHeader->mPlayerKeyCount++; aHeader->mPlayerSectionLength += writtenLen; theReport->mCurEntityKeyCount++; sciSerializeInt16((gsi_u8 *)&theReport->mBuffer.mData[theReport->mCurEntityStartPos], (gsi_i16)theReport->mCurEntityKeyCount); } else if (theReport->mReportState == SCIReportState_TEAMDATA) { aHeader->mTeamKeyCount++; aHeader->mTeamSectionLength += writtenLen; theReport->mCurEntityKeyCount++; sciSerializeInt16((gsi_u8 *)&theReport->mBuffer.mData[theReport->mCurEntityStartPos], (gsi_i16)theReport->mCurEntityKeyCount); } // Needs real error handling code or an assertion on a non-constant expression //else // GS_ASSERT(0); // invalid state for writing key/value pairs! // Write the data sciSerializeInt16((gsi_u8 *)&theReport->mBuffer.mData[theReport->mBuffer.mPos], (gsi_i16)theKeyId); theReport->mBuffer.mPos += sizeof(gsi_u16); sciSerializeInt16((gsi_u8 *)&theReport->mBuffer.mData[theReport->mBuffer.mPos], theKeyType); theReport->mBuffer.mPos += sizeof(gsi_u16); sciSerializeFloat((gsi_u8 *)&theReport->mBuffer.mData[theReport->mBuffer.mPos], theValue); theReport->mBuffer.mPos += sizeof(float); return SCResult_NO_ERROR; }
void ServerBrowserSortA(ServerBrowser sb, SBBool ascending, const char *sortkey, SBCompareMode comparemode) { SortInfo info; info.comparemode = comparemode; #ifdef GSI_UNICODE GS_ASSERT(sortkey != NULL && _tcslen((const unsigned short *)sortkey) <= SORTKEY_LENGTH); _tcscpy(info.sortkey, (const unsigned short *)sortkey); #else GS_ASSERT(sortkey != NULL && _tcslen(sortkey) <= SORTKEY_LENGTH); _tcscpy(info.sortkey, sortkey); #endif SBServerListSort(&sb->list, ascending, info); }