//------------------------------------------------------------------------------ int InitLight(void) { int err = 0; memset(leds, 0, sizeof(leds)); // Set P1.0 to output direction to drive red LED GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0); // Configure SysTick SysTick_enableModule(); SysTick_setPeriod(16000); // with a 68 MHz clock, this period is 1 ms SysTick_enableInterrupt(); // MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableMaster(); initStrip(); // ***** HAVE YOU SET YOUR NUM_LEDS DEFINE IN WS2812.C? ****** // set strip color red fillStrip(0xFF, 0x00, 0x00, 0x00); // show the strip showStrip(); // gradually fill for ever and ever u_int numLEDs = 7; gradualFill(numLEDs, 0x0F, 0x00, 0x00, 0x00); // red return err; }
/** * Main routine */ int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT if (CALBC1_16MHZ==0xFF) // If calibration constant erased { while(1); // do not load, trap CPU!! } BCSCTL1 = CALBC1_16MHZ; // Set DCO DCOCTL = CALDCO_16MHZ; P1DIR = BIT0 + BIT6; // P1.0 and P1.6 are the red+green LEDs P1OUT = BIT0 + BIT6; // All LEDs off uart_init(); //register ISR called when data was received uart_set_rx_isr_ptr(uart_rx_isr); // initialize LED strip initStrip(); // ***** HAVE YOU SET YOUR NUM_LEDS DEFINE IN WS2812.C? ****** //fillStrip( 0x00, 0x00, 0xFF); //showStrip(); __bis_SR_register(GIE); }
void MapChunk::removeHole(int i, int j) { holes = holes & ~((1 << ((j * 4) + i))); initStrip(); }
MapChunk::MapChunk(MapTile *maintile, MPQFile *f, bool bigAlpha) : textureSet(new TextureSet) , mt(maintile) , mBigAlpha(bigAlpha) { uint32_t fourcc; uint32_t size; hasMCCV = false; f->read(&fourcc, 4); f->read(&size, 4); assert(fourcc == 'MCNK'); size_t lastpos = f->getPos() + size; f->read(&header, 0x80); Flags = header.flags; areaID = header.areaid; if (Environment::getInstance()->areaIDColors.find(areaID) == Environment::getInstance()->areaIDColors.end()) { Vec3D newColor = Vec3D(misc::randfloat(0.0f, 1.0f), misc::randfloat(0.0f, 1.0f), misc::randfloat(0.0f, 1.0f)); Environment::getInstance()->areaIDColors.insert(std::pair<int, Vec3D>(areaID, newColor)); } Environment::getInstance()->selectedAreaID = areaID; //The last loaded is selected on start. zbase = header.zpos; xbase = header.xpos; ybase = header.ypos; px = header.ix; py = header.iy; holes = header.holes; // correct the x and z values ^_^ zbase = zbase*-1.0f + ZEROPOINT; xbase = xbase*-1.0f + ZEROPOINT; vmin = Vec3D(9999999.0f, 9999999.0f, 9999999.0f); vmax = Vec3D(-9999999.0f, -9999999.0f, -9999999.0f); while (f->getPos() < lastpos) { f->read(&fourcc, 4); f->read(&size, 4); size_t nextpos = f->getPos() + size; if (fourcc == 'MCNR') { nextpos = f->getPos() + 0x1C0; // size fix // normal vectors char nor[3]; Vec3D *ttn = mNormals; for (int j = 0; j<17; ++j) { for (int i = 0; i<((j % 2) ? 8 : 9); ++i) { f->read(nor, 3); // order X,Z,Y // *ttn++ = Vec3D((float)nor[0]/127.0f, (float)nor[2]/127.0f, (float)nor[1]/127.0f); *ttn++ = Vec3D(-nor[1] / 127.0f, nor[2] / 127.0f, -nor[0] / 127.0f); } } } else if (fourcc == 'MCVT') { Vec3D *ttv = mVertices; // vertices for (int j = 0; j < 17; ++j) { for (int i = 0; i < ((j % 2) ? 8 : 9); ++i) { float h, xpos, zpos; f->read(&h, 4); xpos = i * UNITSIZE; zpos = j * 0.5f * UNITSIZE; if (j % 2) { xpos += UNITSIZE*0.5f; } Vec3D v = Vec3D(xbase + xpos, ybase + h, zbase + zpos); *ttv++ = v; vmin.y = std::min(vmin.y, v.y); vmax.y = std::max(vmax.y, v.y); } } vmin.x = xbase; vmin.z = zbase; vmax.x = xbase + 8 * UNITSIZE; vmax.z = zbase + 8 * UNITSIZE; r = (vmax - vmin).length() * 0.5f; } else if (fourcc == 'MCLY') { textureSet->initTextures(f, mt, size); } else if (fourcc == 'MCSH') { // shadow map 64 x 64 f->read(mShadowMap, 0x200); f->seekRelative(-0x200); unsigned char sbuf[64 * 64], *p, c[8]; p = sbuf; for (int j = 0; j<64; ++j) { f->read(c, 8); for (int i = 0; i<8; ++i) { for (int b = 0x01; b != 0x100; b <<= 1) { *p++ = (c[i] & b) ? 85 : 0; } } } glGenTextures(1, &shadow); glBindTexture(GL_TEXTURE_2D, shadow); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 64, 64, 0, GL_ALPHA, GL_UNSIGNED_BYTE, sbuf); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } else if (fourcc == 'MCAL') { textureSet->initAlphamaps(f, header.nLayers, mBigAlpha); } else if (fourcc == 'MCCV') { if (!(Flags & FLAG_MCCV)) Flags |= FLAG_MCCV; hasMCCV = true; mccv.resize(mapbufsize); size = std::min<int>(size, mapbufsize * 4); f->read(mccv.data(), size); auto numEntries = size / 4; for (auto i = numEntries; i < mapbufsize; ++i) { mccv[i] = 0x00FFFFFF; } for (int i = 0; i < mapbufsize; ++i) mccv[i] = Reverse(mccv[i], true); } f->seek(nextpos); } if (!hasMCCV) { if (!(Flags & FLAG_MCCV)) Flags |= FLAG_MCCV; mccv.assign(mapbufsize, 0x00FFFFFF); } // create vertex buffers glGenBuffers(1, &vertices); glGenBuffers(1, &normals); glGenBuffers(1, &mccvEntry); glBindBuffer(GL_ARRAY_BUFFER, vertices); glBufferData(GL_ARRAY_BUFFER, sizeof(mVertices), mVertices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, normals); glBufferData(GL_ARRAY_BUFFER, sizeof(mNormals), mNormals, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, mccvEntry); glBufferData(GL_ARRAY_BUFFER, mapbufsize * sizeof(UINT32), mccv.data(), GL_STATIC_DRAW); initStrip(); vcenter = (vmin + vmax) * 0.5f; nameID = SelectionNames.add(this); Vec3D *ttv = mMinimap; // vertices for (int j = 0; j<17; ++j) { for (int i = 0; i < ((j % 2) ? 8 : 9); ++i) { float xpos, zpos; //f->read(&h,4); xpos = i * 0.125f; zpos = j * 0.5f * 0.125f; if (j % 2) { xpos += 0.125f*0.5f; } Vec3D v = Vec3D(xpos + px, zpos + py, -1); *ttv++ = v; } } if ((Flags & 1) == 0) { /** We have no shadow map (MCSH), so we got no shadows at all! ** ** This results in everything being black.. Yay. Lets fake it! **/ for (size_t i = 0; i < 512; ++i) mShadowMap[i] = 0; unsigned char sbuf[64 * 64]; for (size_t j = 0; j < 4096; ++j) sbuf[j] = 0; glGenTextures(1, &shadow); glBindTexture(GL_TEXTURE_2D, shadow); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 64, 64, 0, GL_ALPHA, GL_UNSIGNED_BYTE, sbuf); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } float ShadowAmount; for (int j = 0; j<mapbufsize; ++j) { //tm[j].z=tv[j].y; ShadowAmount = 1.0f - (-mNormals[j].x + mNormals[j].y - mNormals[j].z); if (ShadowAmount<0) ShadowAmount = 0.0f; if (ShadowAmount>1.0) ShadowAmount = 1.0f; ShadowAmount *= 0.5f; //ShadowAmount=0.2; mFakeShadows[j].x = 0; mFakeShadows[j].y = 0; mFakeShadows[j].z = 0; mFakeShadows[j].w = ShadowAmount; } glGenBuffers(1, &minimap); glGenBuffers(1, &minishadows); glBindBuffer(GL_ARRAY_BUFFER, minimap); glBufferData(GL_ARRAY_BUFFER, sizeof(mMinimap), mMinimap, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, minishadows); glBufferData(GL_ARRAY_BUFFER, sizeof(mFakeShadows), mFakeShadows, GL_STATIC_DRAW); }
void MapChunk::addHole(int i, int j) { holes = holes | ((1 << ((j * 4) + i))); initStrip(); }