///////////////////////////////////// // Name: MDLSetTexture // Purpose: sets/change model's // texture within material // index // Output: model's texture change // Return: RETCODE_SUCCESS if success ///////////////////////////////////// PUBLIC RETCODE MDLSetTexture(hMDL model, int materialInd, hTXT texture) { //allocate textures if there is none //set it automatically to one if(model->numMaterial == 0) { model->numMaterial = 1; if(MemAlloc((void**)&model->textures, sizeof(hTXT)*model->numMaterial, M_ZERO) != RETCODE_SUCCESS) { ASSERT_MSG(0, "Unable to allocate model textures", "Error in MDLSetTexture"); return RETCODE_FAILURE; } MemSetPattern(model->textures, "MDLTXT"); model->textures[0] = texture; TextureAddRef(model->textures[0]); } else { if(materialInd >= model->numMaterial) { ASSERT_MSG(0, "Bad material index", "Error in MDLSetTexture"); return RETCODE_FAILURE; } TextureDestroy(&model->textures[materialInd]); model->textures[materialInd] = texture; TextureAddRef(model->textures[materialInd]); } return RETCODE_SUCCESS; }
TRenderEntity *RenderEntityCreate2D(const uint32 pWidth, const uint32 pHeight, const char *pFileName) { TTexture *lTexture = TextureCreate(pFileName, false); if(lTexture==NULL) return NULL; TMaterial *lMaterial = MaterialCreate(); MaterialAddTexture(lMaterial, lTexture); TGeom *lQuad = GeomCreateQuad(pWidth, pHeight); GeomSetMaterial(lQuad, lMaterial); TRenderEntity *this = RenderEntityCreate(); RenderEntitySetGeometry(this, lQuad); RenderEntityMove2D(this, pWidth/2.0f, pHeight/2.0f); this->mWidth = pWidth; this->mHeight= pHeight; TextureDestroy(lTexture); MaterialDestroy(lMaterial); GeomDestroy(lQuad); CLASS_INSTANCE(); }
///////////////////////////////////// // Name: MDLSetTexture // Purpose: sets/change model's // texture within material // index // Output: model's texture change // Return: RETCODE_SUCCESS if success ///////////////////////////////////// PUBLIC RETCODE MDLSetTexture(hMDL model, int materialInd, hTXT texture) { //allocate textures if there is none //set it automatically to one if(model->numMaterial == 0) { model->numMaterial = 1; model->textures = (hTXT*)GFX_MALLOC(sizeof(hTXT)*model->numMaterial); if(!model->textures) { ASSERT_MSG(0, "Unable to allocate model textures", "Error in MDLSetTexture"); return RETCODE_FAILURE; } model->textures[0] = texture; TextureAddRef(model->textures[0]); } else { if(materialInd >= model->numMaterial) { ASSERT_MSG(0, "Bad material index", "Error in MDLSetTexture"); return RETCODE_FAILURE; } TextureDestroy(&model->textures[materialInd]); model->textures[materialInd] = texture; TextureAddRef(model->textures[materialInd]); } return RETCODE_SUCCESS; }
TRenderEntity *RenderEntityCreateQuadTextured(const uint32 pSizeX, const uint32 pSizeY, const char *pFileName) { TTexture *lTexture = TextureCreate(pFileName, false); if(lTexture==NULL) return NULL; TMaterial *lMaterial = MaterialCreate(); MaterialAddTexture(lMaterial, lTexture); TGeom *lQuad = GeomCreateQuad(pSizeX, pSizeY); GeomSetMaterial(lQuad, lMaterial); GeomSetTexCoord(lQuad, 0, 0.0f, 0.0f); GeomSetTexCoord(lQuad, 1, 1.0f, 0.0f); GeomSetTexCoord(lQuad, 2, 1.0f, 1.0f); GeomSetTexCoord(lQuad, 3, 0.0f, 1.0f); TRenderEntity *this = RenderEntityCreate(); RenderEntitySetGeometry(this, lQuad); TextureDestroy(lTexture); MaterialDestroy(lMaterial); GeomDestroy(lQuad); CLASS_INSTANCE(); }
PRIVATE void _destroyMdl(hMDL *model) //this will destroy the model, will not search list { if(*model) { if((*model)->mesh) (*model)->mesh->Release(); if((*model)->frames) { for(int i = 0; i < (*model)->numFrames; i++) { if((*model)->frames[i].frameMesh) {(*model)->frames[i].frameMesh->Release();} if((*model)->frames[i].adjacencyBuffer) {(*model)->frames[i].adjacencyBuffer->Release();} } MemFree((void**)&(*model)->frames); } if((*model)->textures) { for(int i = 0; i < (*model)->numMaterial; i++) TextureDestroy(&(*model)->textures[i]); MemFree((void**)&(*model)->textures); } if((*model)->adjacencyBuffer) (*model)->adjacencyBuffer->Release(); if((*model)->materials) MemFree((void**)&(*model)->materials); MemFree((void**)model); } }
ShroomShooter::~ShroomShooter() { if(m_spitMdl) MDLDestroy(&m_spitMdl); if(m_spitFXTxt) TextureDestroy(&m_spitFXTxt); }
///////////////////////////////////// // Name: StageSelectDestroy // Purpose: destroys the stage select // stuff, call this after done // with game // Output: stages destroyed // Return: none ///////////////////////////////////// PUBLIC void StageSelectDestroy() { for(int i = 0; i < g_stages.size(); i++) { if(g_stages[i].mapImg) TextureDestroy(&g_stages[i].mapImg); } g_stages.clear(); }
///////////////////////////////////// // Name: SkyBoxDestroy // Purpose: destroys the skybox // Output: skybox destroyed // Return: none ///////////////////////////////////// PUBLIC void SkyBoxDestroy() { for(int i = 0; i < eSkyNumSide; i++) { if(g_pSkyVtxBuff[i]) { g_pSkyVtxBuff[i]->Release(); g_pSkyVtxBuff[i] = 0; } if(g_skyTextures[i]) { TextureDestroy(&g_skyTextures[i]); g_skyTextures[i] = 0; } } }
RETCODE World::EntityLoad_Sign(hQBSP qbsp, const EntityParse & entityDat) { hTXT txt; int r,g,b,a; //create new sign Sign *newObj = new Sign; assert(newObj); /////////////////////////////////////////////////////// //load up the common stuff EntityLoad_CommonObject(qbsp, entityDat, dynamic_cast<Object *>(newObj)); const char *pStr; /////////////////////////////////////////////////////// //load image pStr = entityDat.GetVal("image"); if(pStr) { string imgPath = GAMEFOLDER; imgPath += "\\"; imgPath += pStr; txt = TextureCreate(0, imgPath.c_str(), false, 0); } /////////////////////////////////////////////////////// //get color pStr = entityDat.GetVal("color"); if(pStr) { sscanf(pStr, "%d %d %d %d", &r,&g,&b,&a); } if(txt) { float sX = (SCRN_W/2) - (TextureGetWidth(txt)/2); float sY = (SCRN_H/2) - (TextureGetHeight(txt)/2); float eX = sX + TextureGetWidth(txt); float eY = sY + TextureGetHeight(txt); sX /= SCRN_W; sY /= SCRN_H; eX /= SCRN_W; eY /= SCRN_H; newObj->SetImageDisplay(ImageDisplayAdd(txt, sX,sY,eX,eY, r,g,b,a)); TextureDestroy(&txt); } return RETCODE_SUCCESS; }
///////////////////////////////////// // Name: OBJSetTexture // Purpose: change obj's // texture within material // index // Output: obj's texture change // Return: RETCODE_SUCCESS if success ///////////////////////////////////// PUBLIC RETCODE OBJSetTexture(hOBJ obj, int materialInd, hTXT texture) { //allocate textures if there is none //set it automatically to one if(obj->theMdl->numMaterial > 0) { if(materialInd >= obj->theMdl->numMaterial) { ASSERT_MSG(0, "Bad material index", "Error in OBJSetTexture"); return RETCODE_FAILURE; } TextureDestroy(&obj->textures[materialInd]); obj->textures[materialInd] = texture; TextureAddRef(obj->textures[materialInd]); } return RETCODE_SUCCESS; }
PROTECTED void _destroyObj(hOBJ *obj) //this will destroy the object, will not search list { if(*obj) { GFXPageRemove(&(*obj)->key); //go through object's children and clear those out if((*obj)->objNode) { hOBJ thisObj; for(LISTPTR::iterator i = (*obj)->objNode->begin(); i != (*obj)->objNode->end(); ++i) { thisObj = (hOBJ)(*i); _destroyObj(&thisObj); } delete (*obj)->objNode; } if((*obj)->theMdl) { if((*obj)->materials) GFX_FREE((*obj)->materials); if((*obj)->textures) { for(int i = 0; i < (*obj)->theMdl->numMaterial; i++) TextureDestroy(&(*obj)->textures[i]); GFX_FREE((*obj)->textures); } MDLDestroy(&(*obj)->theMdl); } if((*obj)->states) GFX_FREE((*obj)->states); if((*obj)->joints) GFX_FREE((*obj)->joints); GFX_FREE(*obj); obj=0; } }
TRenderEntity *RenderEntityCreateCubeTextured(const uint32 pSizeX, const uint32 pSizeY, const uint32 pSizeZ, const char *pFileName) { TTexture *lTexture = TextureCreate(pFileName, false); if(lTexture==NULL) return NULL; TMaterial *lMaterial = MaterialCreate(); MaterialAddTexture(lMaterial, lTexture); TGeom *lCube = GeomCreateCube(pSizeX, pSizeY, pSizeZ); GeomSetMaterial(lCube, lMaterial); TRenderEntity *this = RenderEntityCreate(); RenderEntitySetGeometry(this, lCube); TextureDestroy(lTexture); MaterialDestroy(lMaterial); GeomDestroy(lCube); CLASS_INSTANCE(); }
PRIVATE void _destroyMdl(hMDL *model) //this will destroy the model, will not search list { if(*model) { MeshDestroy(&(*model)->mesh); if((*model)->frames) { for(int i = 0; i < (*model)->numFrames; i++) MeshDestroy(&(*model)->frames[i].frameMesh); GFX_FREE((*model)->frames); } if((*model)->textures) { for(int i = 0; i < (*model)->numMaterial; i++) TextureDestroy(&(*model)->textures[i]); GFX_FREE((*model)->textures); } if((*model)->materials) GFX_FREE((*model)->materials); if((*model)->joints) { for(int i = 0; i < (*model)->numJoints; i++) JointDestroy(&(*model)->joints[i]); GFX_FREE((*model)->joints); } GFX_FREE(*model); model=0; } }
Spit::~Spit() { if(m_trailTxt) TextureDestroy(&m_trailTxt); }
PROTECTED RETCODE fxGas2Func(hPARFX thisPARFX, DWORD message, LPARAM dumbParam, WPARAM otherParam) { switch(message) { case PARFXM_CREATE: { float center[eMaxPt]; hOBJ obj = OBJQuery(&thisPARFX->objKey); fxGas2_init *init = (fxGas2_init *)dumbParam; if(!init) return RETCODE_FAILURE; //set up the main particle if(MemAlloc(&thisPARFX->data, sizeof(fxGas2), M_ZERO) != RETCODE_SUCCESS) { ASSERT_MSG(0, "Unable to allocate gas data", "fxGas2Func"); return RETCODE_FAILURE; } fxGas2 *data = (fxGas2 *)thisPARFX->data; data->gasTxt = init->gasTxt; TextureAddRef(data->gasTxt); data->size = init->size; data->maxParticle = init->maxParticle; //translate the bounds if obj is specified if(obj) OBJGetLoc(obj, center); else memcpy(center, init->center, sizeof(float)*eMaxPt); //allocate the particle gases if(MemAlloc((void**)&data->bunchOgas, sizeof(fxGas2_par)*data->maxParticle, M_ZERO) != RETCODE_SUCCESS) { ASSERT_MSG(0, "Unable to allocate gas particles", "fxGas2Func"); return RETCODE_FAILURE; } //create vertex buffer //_GFXCheckError(HRESULT hr, bool displayMsg, const char *header) if(_GFXCheckError(g_p3DDevice->CreateVertexBuffer(sizeof(fxGas_vtx)*data->maxParticle, D3DUSAGE_POINTS, FXGASVTXFLAG, D3DPOOL_MANAGED, &data->gasVtx), true, "fxGas2Func")) return RETCODE_FAILURE; //initialize each gas particle for(int i = 0; i < data->maxParticle; i++) _fxGas2InitParticle(init, center, &data->bunchOgas[i]); } break; case PARFXM_UPDATE: { fxGas2 *data = (fxGas2 *)thisPARFX->data; fxGas_vtx *pGasVtx; if(FAILED(data->gasVtx->Lock(0,0, (BYTE**)&pGasVtx, 0))) { ASSERT_MSG(0, "Unable to lock gas particle vtx", "fxGas2Func"); return RETCODE_FAILURE; } data->numAlive=0; for(int i = 0; i < data->maxParticle; i++) { if(_fxGas2UpdateParticle(&data->bunchOgas[i], data->size)) { memcpy(&pGasVtx[i], &data->bunchOgas[i].curVtx, sizeof(fxGas_vtx)); data->numAlive++; } } data->gasVtx->Unlock(); if(data->numAlive==0) return RETCODE_BREAK; } break; case PARFXM_DISPLAY: { //push world stack and set this object's world mtx g_pWrldStack->Push(); g_pWrldStack->LoadIdentity(); //do transformations g_p3DDevice->SetTransform(D3DTS_WORLD, g_pWrldStack->GetTop()); DWORD srcBlend, destBlend; fxGas2 *data = (fxGas2 *)thisPARFX->data; //disable light if(!TESTFLAGS(g_FLAGS, GFX_LIGHTDISABLE)) g_p3DDevice->SetRenderState(D3DRS_LIGHTING,FALSE); TextureSet(data->gasTxt, 0); g_p3DDevice->GetRenderState( D3DRS_SRCBLEND, &srcBlend ); g_p3DDevice->GetRenderState( D3DRS_DESTBLEND, &destBlend ); g_p3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); g_p3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); g_p3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); g_p3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE ); g_p3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE ); g_p3DDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.08f) ); g_p3DDevice->SetRenderState( D3DRS_POINTSIZE_MAX, FtoDW(1000.0f) ); g_p3DDevice->SetRenderState( D3DRS_POINTSCALE_A, FtoDW(0.00f) ); g_p3DDevice->SetRenderState( D3DRS_POINTSCALE_B, FtoDW(0.00f) ); g_p3DDevice->SetRenderState( D3DRS_POINTSCALE_C, FtoDW(1.00f) ); g_p3DDevice->SetStreamSource( 0, data->gasVtx, sizeof(fxGas_vtx) ); g_p3DDevice->SetVertexShader( FXGASVTXFLAG ); if(FAILED(g_p3DDevice->DrawPrimitive( D3DPT_POINTLIST, 0, data->numAlive))) { ASSERT_MSG(0, "Failed to draw particles", "fxGasFunc"); return RETCODE_FAILURE; } g_p3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); g_p3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE ); g_p3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE, FALSE ); g_p3DDevice->SetRenderState( D3DRS_SRCBLEND, srcBlend ); g_p3DDevice->SetRenderState( D3DRS_DESTBLEND, destBlend ); //enable light again, if flag is set if(!TESTFLAGS(g_FLAGS, GFX_LIGHTDISABLE)) g_p3DDevice->SetRenderState(D3DRS_LIGHTING,TRUE); TextureSet(0, 0); //take this junk out! g_pWrldStack->Pop(); } break; case PARFXM_DESTROY: { fxGas2 *data = (fxGas2 *)thisPARFX->data; if(data) { if(data->bunchOgas) MemFree((void**)&data->bunchOgas); TextureDestroy(&data->gasTxt); if(data->gasVtx) data->gasVtx->Release(); } } break; } return RETCODE_SUCCESS; }
PROTECTED RETCODE fxSmokeFunc(hPARFX thisPARFX, DWORD message, LPARAM dumbParam, WPARAM otherParam) { fxSmoke *thisData = (fxSmoke *)thisPARFX->data; switch(message) { case PARFXM_UPDATE: { //create a particle if there are not enough smokes if(thisData->smokes->size() < thisData->maxParticle && thisData->bRepeat && dumbParam != PARFX_UPDATE_DEAD) { if(TimeElapse(&thisData->spawnDelay)) { float center[eMaxPt] = {thisData->sLoc[eX], thisData->sLoc[eY], thisData->sLoc[eZ]}; float end[eMaxPt] = {thisData->eLoc[eX], thisData->eLoc[eY], thisData->eLoc[eZ]}; hOBJ obj = PARFXGetOBJ(thisPARFX); if(obj) { PARFXGetOBJLoc(thisPARFX, obj, center); if(thisData->eJointInd != -1) { OBJJointGetWorldLoc(obj, thisData->eJointInd, end); } } _fxSmokeAppend(thisData, center, end); } } //update particles from list fxSmokeList::iterator nextIt; for(fxSmokeList::iterator i = thisData->smokes->begin(); i != thisData->smokes->end();) { nextIt = i; nextIt++; //update this puff and see if it needs to be removed if(_fxSmokeUpdate(thisData, &(*i))) thisData->smokes->erase(i); i = nextIt; } if(thisData->smokes->size() == 0 && dumbParam == PARFX_UPDATE_DEAD) return RETCODE_BREAK; } break; case PARFXM_DISPLAY: { for(fxSmokeList::iterator i = thisData->smokes->begin(); i != thisData->smokes->end(); i++) TextureBltBillboard(thisData->smokeTxt, (*i).loc, thisData->size, (*i).clr); } break; case PARFXM_CREATE: { fxSmoke_init *initDat = (fxSmoke_init *)dumbParam; fxSmoke *newData = (fxSmoke *)GFX_MALLOC(sizeof(fxSmoke)); if(!newData) return RETCODE_FAILURE; newData->smokeTxt = initDat->smokeTxt; TextureAddRef(newData->smokeTxt); newData->r = initDat->r/255.0f; newData->g = initDat->g/255.0f; newData->b = initDat->b/255.0f; TimeInit(&newData->spawnDelay, initDat->spawnDelay); newData->spdDelay = initDat->spdDelay; newData->fadeDelay = initDat->fadeDelay; newData->size = initDat->size; memcpy(newData->min, initDat->min, sizeof(initDat->min)); memcpy(newData->max, initDat->max, sizeof(initDat->max)); memcpy(newData->sLoc, initDat->sLoc, sizeof(initDat->sLoc)); memcpy(newData->eLoc, initDat->eLoc, sizeof(initDat->eLoc)); newData->eJointInd = initDat->eJointInd; newData->maxParticle = initDat->maxParticle; newData->axis = initDat->axis; newData->bRepeat = initDat->bRepeat; newData->smokes = new fxSmokeList; if(!newData->smokes) return RETCODE_FAILURE; thisPARFX->data = newData; } break; case PARFXM_DESTROY: if(thisData) { TextureDestroy(&thisData->smokeTxt); if(thisData->smokes) delete thisData->smokes; } break; } return RETCODE_SUCCESS; }
PROTECTED RETCODE fxLightningYFunc(hPARFX thisPARFX, DWORD message, LPARAM dumbParam, WPARAM otherParam) { fxLightningY *thisData = (fxLightningY *)thisPARFX->data; switch(message) { case PARFXM_UPDATE: { double t = TimeGetTime(&thisData->onTimer)/TimeGetDelay(&thisData->onTimer); if(t > 1){ t = 1; TimeReset(&thisData->onTimer); } //update alpha if(thisData->clr[eA] < 1 && dumbParam != PARFX_UPDATE_DEAD) { thisData->clr[eA] = t; if(thisData->clr[eA] == 1) { TimeReset(&thisData->onTimer); } } else if(thisData->clr[eA] > 0 && dumbParam == PARFX_UPDATE_DEAD) { thisData->clr[eA] = 1.0f - t; if(thisData->clr[eA] == 0) { TimeReset(&thisData->onTimer); } } ///////////////////////////////////////////////////////////////// //update nodes float trans[eMaxPt] = {0}; hOBJ obj = PARFXGetOBJ(thisPARFX); if(obj) { PARFXGetOBJLoc(thisPARFX, obj, trans); } for(int i = 0; i < thisData->numNodes; i++) { t = TimeGetTime(&thisData->Nodes[i].timeMove)/TimeGetDelay(&thisData->Nodes[i].timeMove); if(t > 1) t = 1; thisData->Nodes[i].curLoc[eX] = thisData->Nodes[i].sLoc[eX] + t*(thisData->Nodes[i].eLoc[eX] - thisData->Nodes[i].sLoc[eX]); thisData->Nodes[i].curLoc[eZ] = thisData->Nodes[i].sLoc[eZ] + t*(thisData->Nodes[i].eLoc[eZ] - thisData->Nodes[i].sLoc[eZ]); if(t == 1) { TimeReset(&thisData->Nodes[i].timeMove); //our new start memcpy(thisData->Nodes[i].sLoc, thisData->Nodes[i].curLoc, sizeof(thisData->Nodes[i].sLoc)); //our new end thisData->Nodes[i].eLoc[eX] = _GFXMathRand(thisData->min[eX], thisData->max[eX]) + trans[eX]; thisData->Nodes[i].eLoc[eY] = thisData->min[eY] + ((float)i/(float)thisData->numNodes)*(thisData->max[eY] - thisData->min[eY]) + trans[eY]; thisData->Nodes[i].eLoc[eZ] = _GFXMathRand(thisData->min[eZ], thisData->max[eZ]) + trans[eZ]; } } if(thisData->clr[eA] == 0 && dumbParam == PARFX_UPDATE_DEAD) { return RETCODE_BREAK; } } break; case PARFXM_DISPLAY: if(FrustrumCheckBox( thisData->min[eX], thisData->min[eY], thisData->min[eZ], thisData->max[eX], thisData->max[eY], thisData->max[eZ])) { float t = 0, max=thisData->maxParticle; D3DXVECTOR3 ptOut, pt0, pt1, pt2, pt3; float particleCount=0; int prevInd=0, ind=0, nextInd=1, next2Ind=2; do { memcpy((float*)pt0, thisData->Nodes[prevInd].curLoc, sizeof(thisData->Nodes[prevInd].curLoc)); memcpy((float*)pt1, thisData->Nodes[ind].curLoc, sizeof(thisData->Nodes[ind].curLoc)); memcpy((float*)pt2, thisData->Nodes[nextInd].curLoc, sizeof(thisData->Nodes[nextInd].curLoc)); memcpy((float*)pt3, thisData->Nodes[next2Ind].curLoc, sizeof(thisData->Nodes[next2Ind].curLoc)); //cat-mull-rom curve magic D3DXVec3CatmullRom(&ptOut, &pt0, &pt1, &pt2, &pt3, t); //draw the darn thing TextureBltBillboard(thisData->lightningTxt, (float*)ptOut, thisData->scale, thisData->clr); particleCount++; t = particleCount/max; if(t > 1) { ind++; particleCount = 0; t = 0; } prevInd = ind - 1; if(prevInd < 0) prevInd = 0; nextInd = ind + 1; if(nextInd >= thisData->numNodes) nextInd = thisData->numNodes-1; next2Ind = ind + 2; if(next2Ind >= thisData->numNodes) next2Ind = thisData->numNodes-1; } while(ind < thisData->numNodes); } break; case PARFXM_CREATE: { fxLightningY_init *initDat = (fxLightningY_init *)dumbParam; fxLightningY *newData = (fxLightningY *)GFX_MALLOC(sizeof(fxLightningY)); if(!newData) return RETCODE_FAILURE; newData->lightningTxt = initDat->lightningTxt; TextureAddRef(newData->lightningTxt); newData->clr[eR] = initDat->r/255.0f; newData->clr[eG] = initDat->g/255.0f; newData->clr[eB] = initDat->b/255.0f; newData->clr[eA] = 0; newData->scale = initDat->scale; memcpy(newData->min, initDat->min, sizeof(newData->min)); memcpy(newData->max, initDat->max, sizeof(newData->max)); newData->maxParticle = 20;//initDat->maxParticle; TimeInit(&newData->onTimer, initDat->delayOn); TimeReset(&newData->onTimer); newData->delayMove = initDat->delayMove; newData->numNodes = initDat->maxPoint; newData->Nodes = (lightningNode *)GFX_MALLOC(sizeof(lightningNode)*newData->numNodes); if(!newData->Nodes) return RETCODE_FAILURE; //////////////////////////////////////////////////////////////// //initialize the nodes float trans[eMaxPt] = {0}; hOBJ obj = PARFXGetOBJ(thisPARFX); if(obj) { PARFXGetOBJLoc(thisPARFX, obj, trans); } for(int i = 0; i < newData->numNodes; i++) { newData->Nodes[i].sLoc[eX] = _GFXMathRand(newData->min[eX], newData->max[eX]) + trans[eX]; newData->Nodes[i].sLoc[eY] = newData->min[eY] + ((float)i/(float)newData->numNodes)*(newData->max[eY] - newData->min[eY]) + trans[eY]; newData->Nodes[i].sLoc[eZ] = _GFXMathRand(newData->min[eZ], newData->max[eZ]) + trans[eZ]; memcpy(newData->Nodes[i].curLoc, newData->Nodes[i].sLoc, sizeof(newData->Nodes[i].curLoc)); newData->Nodes[i].eLoc[eX] = _GFXMathRand(newData->min[eX], newData->max[eX]) + trans[eX]; newData->Nodes[i].eLoc[eY] = newData->min[eY] + ((float)i/(float)newData->numNodes)*(newData->max[eY] - newData->min[eY]) + trans[eY]; newData->Nodes[i].eLoc[eZ] = _GFXMathRand(newData->min[eZ], newData->max[eZ]) + trans[eZ]; TimeInit(&newData->Nodes[i].timeMove, newData->delayMove); } thisPARFX->data = newData; } break; case PARFXM_DESTROY: { if(thisData) { if(thisData->Nodes) GFX_FREE(thisData->Nodes); if(thisData->lightningTxt) TextureDestroy(&thisData->lightningTxt); } } break; } return RETCODE_SUCCESS; }
PROTECTED RETCODE WinProc(DWORD msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case GMSG_INIT: g_exit=eEXIT_NO; g_timeAmt = (int)lParam; g_bkgrnd = TextureSearch((unsigned int)wParam); TextureAddRef(g_bkgrnd); g_fnt=MenuFontGet(WINFNTIND); TimerInit(&g_delay, 1, WINDELAY); TimerInit(&g_counterDelay, 1000, 10); break; case GMSG_UPDATE: if(g_exit==eEXIT_NO) { if(TimerEllapse(&g_counterDelay)) { if(g_timeAmt > 0) { g_gameScore++; g_timeAmt--; } } if(TimerEllapse(&g_delay) || InputKbAnyKeyReleased()) { g_gameScore += g_timeAmt; g_timeAmt=0; g_exit=eEXIT_OK; } if(g_exit!=eEXIT_NO) _GUTBKFXExitProc(eBKFX_FADEINOUT,0); } break; case GMSG_DISPLAY: { GFXClear(0, 0, 0); //clears screen within rects with given color char buff[MAXCHARBUFF]; SIZE fntSz; float x=GFXGetScrnSize().cx/2; float y=GFXGetScrnSize().cy/4; GFXBltModeEnable(false); TextureStretchBlt(g_bkgrnd, 0,0, GFXGetScrnSize().cx, GFXGetScrnSize().cy, 0,0,0); sprintf(buff, "Time: %d", g_timeAmt); FontGetStrSize(g_fnt, buff, &fntSz); FontPrintf2D(g_fnt, x-(fntSz.cx/2), y, 0x7fffffff, buff); sprintf(buff, "Score: %d", g_gameScore); FontGetStrSize(g_fnt, buff, &fntSz); FontPrintf2D(g_fnt, x-(fntSz.cx/2), y+fntSz.cy, 0x7fffffff, buff); GFXBltModeDisable(); if(_GUTBKFXUpdate() == RETCODE_BREAK && g_exit != eEXIT_NO) { SENDPROCMSG(GMSG_DESTROY, 0, 0); g_gameMaps.curMap++; switch(g_exit) { case eEXIT_OK: //max level if(g_gameMaps.curMap >= g_gameMaps.numMap) { //we finished all the maps! SETPROCTYPE(eWinAll); SENDPROCMSG(GMSG_INIT, 0, 0); } else { SETPROCTYPE(eGame); SENDPROCMSG(GMSG_INIT, 0, 0); } break; } } GFXUpdate(0, 0, 0); //update frame on display } break; case GMSG_LOAD: break; case GMSG_DESTROY: TextureDestroy(&g_bkgrnd); break; } return RETCODE_SUCCESS; }
//Level Start RETCODE MCB_LevelStart(hMENU hMenu, DWORD msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case MENU_MSG_LOAD: { SIZE scrnSize = GFXGetScrnSize(); hCFG cfg = (hCFG)wParam; if(cfg) { char buff[MAXCHARBUFF]={0}; int r,g,b,a; float fntSize; /////////////////////////////////////// // Get Font Title fntSize = CfgGetItemFloat(cfg, LEVEL_START_SECTION, "titleFntSize"); fntSize *= scrnSize.cx; if(CfgGetItemStr(cfg, LEVEL_START_SECTION, "titleFnt", buff)) g_titleFnt = FontCreate(buff, fntSize, 0); if(CfgGetItemStr(cfg, LEVEL_START_SECTION, "titleFntClr", buff)) { sscanf(buff, "%d,%d,%d,%d", &r,&g,&b,&a); g_titleClr = D3DCOLOR_RGBA(r,g,b,a); } /////////////////////////////////////// // Get Font Desc. fntSize = CfgGetItemFloat(cfg, LEVEL_START_SECTION, "descFntSize"); fntSize *= scrnSize.cx; if(CfgGetItemStr(cfg, LEVEL_START_SECTION, "descFnt", buff)) g_descFnt = FontCreate(buff, fntSize, 0); if(CfgGetItemStr(cfg, LEVEL_START_SECTION, "descFntClr", buff)) { sscanf(buff, "%d,%d,%d,%d", &r,&g,&b,&a); g_descClr = D3DCOLOR_RGBA(r,g,b,a); } /////////////////////////////////////// // Get Background img if(CfgGetItemStr(cfg, LEVEL_START_SECTION, "bkImg", buff)) { string imgPath = GAMEFOLDER; imgPath += "\\"; imgPath += buff; g_bkImg = TextureCreate(0, imgPath.c_str(), false, 0); } /////////////////////////////////////// // Load other components g_bkOfs = CfgGetItemFloat(cfg, LEVEL_START_SECTION, "bkOfs"); g_bkOfs *= scrnSize.cx; g_titleSY = CfgGetItemFloat(cfg, LEVEL_START_SECTION, "titleY"); g_titleSY *= scrnSize.cy; if(CfgGetItemStr(cfg, LEVEL_START_SECTION, "descSLoc", buff)) { sscanf(buff, "%f,%f", &g_descLoc.x, &g_descLoc.y); g_descLoc.x *= scrnSize.cx; g_descLoc.y *= scrnSize.cy; } if(CfgGetItemStr(cfg, LEVEL_START_SECTION, "descELoc", buff)) { D3DXVECTOR2 eLoc; sscanf(buff, "%f,%f", &eLoc.x, &eLoc.y); g_descSize.x = (eLoc.x*scrnSize.cx) - g_descLoc.x; g_descSize.y = (eLoc.y*scrnSize.cy) - g_descLoc.y; } } g_world->SetFlag(WORLD_FLAG_INPUT_DISABLE, true); } break; case MENU_MSG_BTN: if(lParam == INP_STATE_RELEASED) { switch(wParam) { case INP_A: case INP_B: case INP_C: case INP_D: case INP_START: g_world->SetFlag(WORLD_FLAG_INPUT_DISABLE, false); MenuExitCurrent(); g_world->CutsceneRemove(); InputClear(); break; } } break; case MENU_MSG_ITEM: g_world->SetFlag(WORLD_FLAG_INPUT_DISABLE, false); MenuExitCurrent(); g_world->CutsceneRemove(); InputClear(); break; case MENU_MSG_UPDATE: switch(wParam) { case MENU_UPDATE_NORMAL: if(INPXKbIsReleased(DIK_ESCAPE) || INPXKbIsReleased(DIK_RETURN)) { g_world->SetFlag(WORLD_FLAG_INPUT_DISABLE, false); MenuExitCurrent(); g_world->CutsceneRemove(); } break; case MENU_UPDATE_ENTERING: case MENU_UPDATE_EXITING: return RETCODE_BREAK; } break; case MENU_MSG_DRAW: if(g_world) { SIZE scrnSize = GFXGetScrnSize(); SIZE fntSize; float fntX, fntY; float bkX, bkY, bkW, bkH; /////////////////////////////////////////// //Display Title const char *titleStr = g_world->GetName(); FontGetStrSize(g_titleFnt, (char*)titleStr, &fntSize); fntX = (scrnSize.cx/2)-(fntSize.cx/2); fntY = g_titleSY; bkX = fntX - g_bkOfs; bkY = fntY - g_bkOfs; bkW = fntSize.cx+(g_bkOfs*2); bkH = fntSize.cy+(g_bkOfs*2); GFXBltModeEnable(0); TextureStretchBlt(g_bkImg, bkX,bkY,bkW,bkH, 0, 0, 0); GFXBltModeDisable(); FontPrintf2D(g_titleFnt, fntX, fntY, g_titleClr, titleStr); /////////////////////////////////////////// //Display Description bkX = g_descLoc.x - g_bkOfs; bkY = g_descLoc.y - g_bkOfs; bkW = g_descSize.x+(g_bkOfs*2); bkH = g_descSize.y+(g_bkOfs*2); GFXBltModeEnable(0); TextureStretchBlt(g_bkImg, bkX,bkY,bkW,bkH, 0, 0, 0); GFXBltModeDisable(); FontTextBox(g_descFnt, g_descLoc.x,g_descLoc.y, g_descLoc.x+g_descSize.x, g_descLoc.y+g_descSize.y, g_descClr, g_world->MapGetDesc()); /////////////////////////////////////////// //Press Any Button To Start FontGetStrSize(g_descFnt, "Press Any Button To Start", &fntSize); fntX = (scrnSize.cx/2)-(fntSize.cx/2); fntY = scrnSize.cy - fntSize.cy; FontPrintf2D(g_descFnt, fntX, fntY, 0xffffffff, "Press Any Button To Start"); } break; case MENU_MSG_DESTROY: if(g_titleFnt) { FontDestroy(&g_titleFnt); g_titleFnt = 0; } if(g_descFnt) { FontDestroy(&g_descFnt); g_descFnt = 0; } if(g_bkImg) { TextureDestroy(&g_bkImg); g_bkImg = 0; } break; } return RETCODE_SUCCESS; }