int main() { double xx[100],yy[100]; float ff[100]; double x,y,z; float f; long index; long i,j; Vector v, normal, position, angle; printf("\n"); printf("-------------------------------------\n"); printf(" PhoSim Unit Testing Framework\n"); printf("-------------------------------------\n\n"); for (i=0;i<100;i++) xx[i]=((double)i)/100.0; for (i=0;i<100;i++) yy[i]=((double)i)/100.0; for (i=0;i<100;i++) ff[i]=((double)i)/100.0; find(xx,100,0.601,&index); unitTestOutput(index,60,"find","Index finding","none"); index=find_linear(xx,100,0.601,&x); unitTestOutput(index,60,"findLinear","Index finding","none"); find_linear_wrap(1.0,0.1,100,&i,&j,&x); unitTestOutput(j,60,"findLinearWrap","Index finding","none"); x=1.0; y=1.0; z=0.0; normalize(&x,&y,&z); unitTestOutput(x,1.0/sqrt(2.0),"normalize","Normalize vector","none"); x=interpolate(yy,xx,0.605,60); unitTestOutput(x,0.605,"interpolate","Interpolate array","none"); x=interpolate_linear(yy,60,60.5); unitTestOutput(x,0.605,"interpolateLinear","Interpolate array","none"); x=interpolate_bilinear(yy,0,0,0.0,60,60.5); unitTestOutput(x,0.605,"interpolateBilinear","Interpolate 2-D array","none"); f=interpolate_bilinear_float_wrap(ff,0,0,1,0.0,60,61,0.5); unitTestOutput((double)f,0.605,"interpolateBilinearFloatWrap","Interpolate 2-D array","none"); v.x=0.0; v.y=1.0/sqrt(2.0); v.z=-1.0/sqrt(2.0); normal.x=0.0; normal.y=0.0; normal.z=1.0; reflect(&v,normal); unitTestOutput(v.z,1/sqrt(2.0),"reflect","Ray component after reflection","none"); v.x=0.0; v.y=1.0/sqrt(2.0); v.z=-1.0/sqrt(2.0); normal.x=0.0; normal.y=0.0; normal.z=1.0; refract(&v,normal,1.0,2.0); unitTestOutput(v.y,1/sqrt(2.0)/2.0,"refract","Ray component after snell's law","none"); position.x=0.; position.y=0.; position.z=0.; angle.x=0; angle.y=1/sqrt(2.0); angle.z=1/sqrt(2.0); propagate(&position,angle,sqrt(2.0)); unitTestOutput(position.y,1.0,"propagate","Ray position after propagation","none"); return(0); }
int CLayerTiles::RenderProperties(CUIRect *pToolBox) { CUIRect Button; bool InGameGroup = !find_linear(m_pEditor->m_Map.m_pGameGroup->m_lLayers.all(), this).empty(); if(m_pEditor->m_Map.m_pGameLayer != this) { if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size() && m_pEditor->m_Map.m_lImages[m_Image]->m_pAutoMapper) { static int s_AutoMapperButton = 0; pToolBox->HSplitBottom(12.0f, pToolBox, &Button); if(m_pEditor->DoButton_Editor(&s_AutoMapperButton, "Auto map", 0, &Button, 0, "")) m_pEditor->PopupSelectConfigAutoMapInvoke(m_pEditor->UI()->MouseX(), m_pEditor->UI()->MouseY()); bool Proceed = m_pEditor->PopupAutoMapProceedOrder(); if(Proceed) { if(m_pEditor->m_Map.m_lImages[m_Image]->m_pAutoMapper->GetType() == IAutoMapper::TYPE_TILESET) { m_pEditor->m_Map.m_lImages[m_Image]->m_pAutoMapper->Proceed(this, m_SelectedRuleSet); return 1; // only close the popup when it's a tileset } else if(m_pEditor->m_Map.m_lImages[m_Image]->m_pAutoMapper->GetType() == IAutoMapper::TYPE_DOODADS) m_pEditor->m_Map.m_lImages[m_Image]->m_pAutoMapper->Proceed(this, m_SelectedRuleSet, m_SelectedAmount); } } } else InGameGroup = false; if(InGameGroup) { pToolBox->HSplitBottom(2.0f, pToolBox, 0); pToolBox->HSplitBottom(12.0f, pToolBox, &Button); static int s_ColclButton = 0; if(m_pEditor->DoButton_Editor(&s_ColclButton, "Game tiles", 0, &Button, 0, "Constructs game tiles from this layer")) m_pEditor->PopupSelectGametileOpInvoke(m_pEditor->UI()->MouseX(), m_pEditor->UI()->MouseY()); int Result = m_pEditor->PopupSelectGameTileOpResult(); if(Result > -1) { CLayerTiles *gl = m_pEditor->m_Map.m_pGameLayer; int w = min(gl->m_Width, m_Width); int h = min(gl->m_Height, m_Height); for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) if(m_pTiles[y*m_Width+x].m_Index) gl->m_pTiles[y*gl->m_Width+x].m_Index = TILE_AIR+Result; return 1; } } enum { PROP_WIDTH=0, PROP_HEIGHT, PROP_SHIFT, PROP_IMAGE, PROP_COLOR, PROP_COLOR_ENV, PROP_COLOR_ENV_OFFSET, NUM_PROPS, }; int Color = 0; Color |= m_Color.r<<24; Color |= m_Color.g<<16; Color |= m_Color.b<<8; Color |= m_Color.a; CProperty aProps[] = { {"Width", m_Width, PROPTYPE_INT_SCROLL, 1, 1000000000}, {"Height", m_Height, PROPTYPE_INT_SCROLL, 1, 1000000000}, {"Shift", 0, PROPTYPE_SHIFT, 0, 0}, {"Image", m_Image, PROPTYPE_IMAGE, 0, 0}, {"Color", Color, PROPTYPE_COLOR, 0, 0}, {"Color Env", m_ColorEnv+1, PROPTYPE_INT_STEP, 0, m_pEditor->m_Map.m_lEnvelopes.size()+1}, {"Color TO", m_ColorEnvOffset, PROPTYPE_INT_SCROLL, -1000000, 1000000}, {0}, }; if(m_pEditor->m_Map.m_pGameLayer == this) // remove the image and color properties if this is the game layer { aProps[3].m_pName = 0; aProps[4].m_pName = 0; } static int s_aIds[NUM_PROPS] = {0}; int NewVal = 0; int Prop = m_pEditor->DoProperties(pToolBox, aProps, s_aIds, &NewVal); if(Prop != -1) m_pEditor->m_Map.m_Modified = true; if(Prop == PROP_WIDTH && NewVal > 1) Resize(NewVal, m_Height); else if(Prop == PROP_HEIGHT && NewVal > 1) Resize(m_Width, NewVal); else if(Prop == PROP_SHIFT) Shift(NewVal); else if(Prop == PROP_IMAGE) { if (NewVal == -1) { m_Texture = IGraphics::CTextureHandle(); m_Image = -1; } else m_Image = NewVal%m_pEditor->m_Map.m_lImages.size(); } else if(Prop == PROP_COLOR) { m_Color.r = (NewVal>>24)&0xff; m_Color.g = (NewVal>>16)&0xff; m_Color.b = (NewVal>>8)&0xff; m_Color.a = NewVal&0xff; }
int CLayerTiles::RenderProperties(CUIRect *pToolBox) { CUIRect Button; pToolBox->HSplitBottom(12.0f, pToolBox, &Button); bool InGameGroup = !find_linear(m_pEditor->m_Map.m_pGameGroup->m_lLayers.all(), this).empty(); if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this || m_pEditor->m_Map.m_pFrontLayer == this || m_pEditor->m_Map.m_pSwitchLayer == this) InGameGroup = false; if(InGameGroup) { static int s_ColclButton = 0; if(m_pEditor->DoButton_Editor(&s_ColclButton, "Game tiles", 0, &Button, 0, "Constructs game tiles from this layer")) m_pEditor->PopupSelectGametileOpInvoke(m_pEditor->UI()->MouseX(), m_pEditor->UI()->MouseY()); int Result = m_pEditor->PopupSelectGameTileOpResult(); switch(Result) { case 4: Result = TILE_FREEZE; break; case 5: Result = TILE_UNFREEZE; break; case 6: Result = TILE_DFREEZE; break; case 7: Result = TILE_DUNFREEZE; break; default: break; } if(Result > -1) { CLayerTiles *gl = m_pEditor->m_Map.m_pGameLayer; int w = min(gl->m_Width, m_Width); int h = min(gl->m_Height, m_Height); for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) if(m_pTiles[y*m_Width+x].m_Index) gl->m_pTiles[y*gl->m_Width+x].m_Index = TILE_AIR+Result; return 1; } } enum { PROP_WIDTH=0, PROP_HEIGHT, PROP_SHIFT, PROP_IMAGE, PROP_COLOR, NUM_PROPS, }; int Color = 0; Color |= m_Color.r<<24; Color |= m_Color.g<<16; Color |= m_Color.b<<8; Color |= m_Color.a; CProperty aProps[] = { {"Width", m_Width, PROPTYPE_INT_SCROLL, 1, 1000000000}, {"Height", m_Height, PROPTYPE_INT_SCROLL, 1, 1000000000}, {"Shift", 0, PROPTYPE_SHIFT, 0, 0}, {"Image", m_Image, PROPTYPE_IMAGE, 0, 0}, {"Color", Color, PROPTYPE_COLOR, 0, 0}, {0}, }; if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this || m_pEditor->m_Map.m_pFrontLayer == this || m_pEditor->m_Map.m_pSwitchLayer == this) // remove the image and color properties if this is the game/tele/speedup/front/switch layer { aProps[3].m_pName = 0; aProps[4].m_pName = 0; } static int s_aIds[NUM_PROPS] = {0}; int NewVal = 0; int Prop = m_pEditor->DoProperties(pToolBox, aProps, s_aIds, &NewVal); if(Prop != -1) m_pEditor->m_Map.m_Modified = true; if(Prop == PROP_WIDTH && NewVal > 1) Resize(NewVal, m_Height); else if(Prop == PROP_HEIGHT && NewVal > 1) Resize(m_Width, NewVal); else if(Prop == PROP_SHIFT) Shift(NewVal); else if(Prop == PROP_IMAGE) { if (NewVal == -1) { m_TexID = -1; m_Image = -1; } else m_Image = NewVal%m_pEditor->m_Map.m_lImages.size(); } else if(Prop == PROP_COLOR) { m_Color.r = (NewVal>>24)&0xff; m_Color.g = (NewVal>>16)&0xff; m_Color.b = (NewVal>>8)&0xff; m_Color.a = NewVal&0xff; }