void operator()(void *ptr) { printf("C++: free() is called by %s() in %s:%d addr:"PTR_FMT"\n", caller_, file_, line_,PTR_CAST(ptr)); free(ptr); }
static Val forward_special_chunk (Agegroup* ag1, Val* chunk, Val tagword) { // ===================== // // Forward a special chunk (suspension or weak pointer). Sib* sib = ag1->sib[ RW_POINTERS_SIB ]; // Special chunks can be updated (modified) // so they have to go in RW_POINTERS_SIB. Val* new_chunk = sib->tospace.first_free; sib->tospace.first_free += SPECIAL_CHUNK_SIZE_IN_WORDS; // All specials are two words. switch (GET_LENGTH_IN_WORDS_FROM_TAGWORD( tagword )) { // case EVALUATED_LAZY_SUSPENSION_CTAG: case UNEVALUATED_LAZY_SUSPENSION_CTAG: // *new_chunk++ = tagword; *new_chunk = *chunk; break; case WEAK_POINTER_CTAG: { // Val v = *chunk; #ifdef DEBUG_WEAKREFS debug_say ("MinorGC: weak [%#x ==> %#x] --> %#x", chunk, new_chunk+1, v); #endif if (! IS_POINTER( v )) { #ifdef DEBUG_WEAKREFS debug_say (" unboxed\n"); #endif // Weak references to unboxed chunks (i.e., immediate Int31) // can never be nullified, since Int31 values, being stored // in-pointer, take no actual heapspace and thus cannot actually // ever get garbage-collected. Consequently, we can just copy // such weakrefs over and skip the rest of our usual processing: // new_chunk[0] = WEAKREF_TAGWORD; new_chunk[1] = v; ++new_chunk; } else { Sibid sibid = SIBID_FOR_POINTER( book_to_sibid__global, v ); Val* vp = PTR_CAST( Val*, v ); if (sibid != AGEGROUP0_SIBID) { // Weakref points to a value in an older heap agegroup. // Since we are only heapcleaning agegroup0 in // this file, the referenced value cannot get // garbage-collected this pass, so we can skip // the usual work to check for that and if necessary // null out the weakref: // #ifdef DEBUG_WEAKREFS debug_say (" old chunk\n"); #endif new_chunk[0] = WEAKREF_TAGWORD; new_chunk[1] = v; ++new_chunk; } else { // if (vp[-1] == FORWARDED_CHUNK_TAGWORD) { // // Reference to a chunk that has already been forwarded. // Note that we have to put the pointer to the non-forwarded // copy of the chunk (i.e, v) into the to-space copy // of the weak pointer, since the heapcleaner has the invariant // that it never sees to-space pointers during sweeping. #ifdef DEBUG_WEAKREFS debug_say (" already forwarded to %#x\n", PTR_CAST( Val, FOLLOW_FORWARDING_POINTER(vp))); #endif new_chunk[0] = WEAKREF_TAGWORD; new_chunk[1] = v; ++new_chunk; } else { // This is the important case: We are copying a weakref // of an agegroup0 value. That agegroup0 value might get // get garbage-collected this pass; if it does, we must null // out the weakref. // // To do this efficiently, as we copy such weakrefs from // agegroup0 into agegroup1 we chain them togther via // their tagword fields with the root pointer kept // in ag1->heap->weakrefs_forwarded_during_heapcleaning. // // At the end of heapcleaning we will consume this chain of // weakrefs in null_out_newly_dead_weakrefs() where // null_out_newly_dead_weakrefs is from src/c/heapcleaner/heapcleaner-stuff.c // we will null out any newly dead weakrefs and then // replace the chainlinks with valid tagwords -- either // WEAKREF_TAGWORD or NULLED_WEAKREF_TAGWORD, // as appropriate, thus erasing our weakref chain and // restoring sanity. // // We mark the chunk reference field in the forwarded copy // to make it look like an Tagged_Int so that the to-space // sweeper does not follow the weak reference. #ifdef DEBUG_WEAKREFS debug_say (" forward\n"); #endif new_chunk[0] = MARK_POINTER(PTR_CAST( Val, ag1->heap->weakrefs_forwarded_during_heapcleaning )); // MARK_POINTER just sets the low bit to 1, making it look like an Int31 value new_chunk[1] = MARK_POINTER( vp ); // MARK_POINTER is from src/c/h/heap-tags.h ag1->heap->weakrefs_forwarded_during_heapcleaning = new_chunk; ++new_chunk; } } } } break; case NULLED_WEAK_POINTER_CTAG: // Shouldn't happen in agegroup0. default: die ( "strange/unexpected special chunk @ %#x; tagword = %#x\n", chunk, tagword ); } // switch (GET_LENGTH_IN_WORDS_FROM_TAGWORD(tagword)) chunk[-1] = FORWARDED_CHUNK_TAGWORD; chunk[ 0] = (Val) (Vunt) new_chunk; return PTR_CAST( Val, new_chunk ); } // fun forward_special_chunk
void TestLevel::setup(){ INFO("Generating Test Level..."); readFile(); initalizeGrid(); createRenders(); createLevel(); INFO("Removal String so less of make"); waterSurfaceManager = WaterSurfaceManagerPtr(new WaterSurfaceManager()); addGameObject(waterSurfaceManager); INFO("Setting up the cameras for the Test Level..."); CameraPtr cam3(new Camera(glm::vec3(16, 30, 0), glm::vec3(16, 15, 6), glm::vec3(0, 1, 0))); cam3->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("CinematicCamera", cam3); setMainCamera("CinematicCamera"); setCullingCamera("CinematicCamera"); CameraPtr cam1(new Camera(glm::vec3(4, 10, -5), glm::vec3(4, 4, -10), glm::vec3(0, 1, 0))); cam1->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("Camera1", cam1); CameraPtr cam2(new Camera(glm::vec3(0, 1, 0), glm::vec3(-6, -3, 6), glm::vec3(0, 1, 0))); cam2->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); l1 = LightPtr(new Light(glm::vec3(1), 30.0f, glm::vec3(0, 30, 0))); l1->setPosition(l1->getDirection()); Uniform3DGridPtr<int> typeGrid = getTypeGrid(); gridCenter = glm::vec3((typeGrid->getMaxX() - typeGrid->getMinX())/2.0f, (typeGrid->getMaxY() - typeGrid->getMinY())/2.0f, (typeGrid->getMinZ() - typeGrid->getMaxZ())/2.0f); l1->setViewMatrix(glm::lookAt( l1->getPosition(), gridCenter, glm::vec3(0, 1, 0))); l1->setProjectionMatrix(glm::ortho<float>(-30,30,-30,30,-70,70)); addLight("Sun", l1); INFO("Setting up the player for the Test Level..."); cinematicPlayer = CinematicPlayerPtr(new CinematicPlayer(cam3)); cinematicPlayer->setup(); addGameObject("cinematicPlayer", cinematicPlayer); player = PlayerPtr(new Player(cam1, 2)); player->setup(); addGameObject("player" , player); CollisionManager::addCollisionObjectToList(player); debugPlayer = DebugPlayerPtr(new DebugPlayer(cam2)); debugPlayer->setup(); addGameObject("debugPlayer" , debugPlayer); addCamera("DebugCamera", cam2); INFO("Creating Switch for the Test Level..."); SwitchPtr s1(new Switch(glm::vec3(0.9f, 0.1f, 0.1f), glm::vec3(29.7, 23, -45), glm::vec3(0,0,1), -20.0f, 1)); s1->setup(); addGameObject("s1", s1); CollisionManager::addCollisionObjectToGrid(s1); std::list<SolidCubePtr> solidCubes; // INFO("Creating Active Terrain for the Test Level..."); for(int i = 1; i < 15; i++) { for(int j = 6; j < 11; j++) { SolidCubePtr at1(new SolidCube(glm::vec3(i*2 + 1, j*2 + 1, -37))); at1->setup(); RenderEngine::getRenderGrid()->removeObject(at1->getObject()); //RenderEngine::getRenderElement("shadow")->removeObject(at1->getObject()); solidCubes.push_back(at1); SolidCubePtr at2(new SolidCube(glm::vec3(i*2 + 1, j*2 + 1, -19))); at2->setup(); RenderEngine::getRenderGrid()->removeObject(at2->getObject()); //RenderEngine::getRenderElement("shadow")->removeObject(at2->getObject()); solidCubes.push_back(at2); } } for(int j = -19; j < -9; j++) { for(int i = 7; i < 13; i++) { SolidCubePtr at1(new SolidCube(glm::vec3(1, i*2 + 1, j*2 + 1))); at1->setup(); RenderEngine::getRenderGrid()->removeObject(at1->getObject()); //RenderEngine::getRenderElement("shadow")->removeObject(at1->getObject()); solidCubes.push_back(at1); SolidCubePtr at2(new SolidCube(glm::vec3(15 * 2 + 1, i*2 + 1, j*2 + 1))); at2->setup(); RenderEngine::getRenderGrid()->removeObject(at2->getObject()); //RenderEngine::getRenderElement("shadow")->removeObject(at2->getObject()); solidCubes.push_back(at2); } } ActiveTerrainPtr a1(new ActiveTerrain(s1, glm::vec3(), glm::vec3(), 50.0f)); a1->setup(); a1->setCubes(solidCubes); addGameObject("a1", a1); PTR_CAST(SolidCube, (*grid)(0, 10, 22))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(0, 10, 23))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(0, 10, 22))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(0, 10, 23))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(1, 4, 11, 11, 22, 23, 1, 0, 0.0f); shearRegion(5, 8, 10, 10, 22, 23, 1, 0, 0.5f); PTR_CAST(SolidCube, (*grid)(0, 10, 4))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(0, 10, 5))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(0, 10, 4))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(0, 10, 5))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(1, 4, 11, 11, 4, 5, 1, 0, 0.0f); shearRegion(5, 8, 10, 10, 4, 5, 1, 0, 0.5f); sky = ObjectPtr(new Object( LoadManager::getMesh("sphere.obj"), MaterialManager::getMaterial("None"))); sky->applyTexture(LoadManager::getTexture("Sky")); sky->enableTexture(); sky->scale(glm::vec3(-50.0f,-50.0f,-50.0f)); sky->translate(Director::getScene()->getCamera()->getEye()); RenderEngine::getRenderElement("textured")->addObject(sky); ExclamationPtr exclamation = ExclamationPtr(new Exclamation(glm::vec3(10, 27, -30))); exclamation->setup(); addGameObject("exclamation", exclamation); }
static Val forward_agegroup0_chunk_to_agegroup1 (Agegroup* ag1, Val v, Task* task, int caller) { // 'task' arg is only for debugging, can be removed in production use. // ===================================== // // Forward pair/record/vector/string 'v' from agegroup0 to agegroup 1. // This involves: // // o Duplicating v in the appropriate agegroup 1 to-space buffer. // o Setting v's tagword to FORWARDED_CHUNK_TAGWORD. // o Setting v's first slot to point to the duplicate. // o Returning a pointer to the duplicate. Val* new_chunk; Vunt len_in_words; Sib* sib; Val* chunk = PTR_CAST(Val*, v); Val tagword = chunk[-1]; switch (GET_BTAG_FROM_TAGWORD( tagword )) { // case PAIRS_AND_RECORDS_BTAG: // len_in_words = GET_LENGTH_IN_WORDS_FROM_TAGWORD( tagword ); #ifdef NO_PAIR_STRIP // 'NO_PAIR_STRIP' appears nowhere else in the codebase. sib = ag1->sib[RO_POINTERS_SIB]; #else if (len_in_words != 2) { sib = ag1->sib[ RO_POINTERS_SIB ]; // This v is not a pair, so fall through to default code. } else { // // This v is a pair, so we'll use special-case code. sib = ag1->sib[ RO_CONSCELL_SIB ]; // We'll copy it into the dedicated pairs-only sib in agegroup1. new_chunk = sib->tospace.first_free; // Where to copy it in that sib. sib->tospace.first_free += 2; // Allocate the space for it. new_chunk[0] = chunk[0]; // Copy first word of pair. new_chunk[1] = chunk[1]; // Copy second word of pair. // Notice that we don't need to copy the tagword -- it is implicit in the fact that we're in the pairsib. // Set up the forward pointer in the old pair: // chunk[-1] = FORWARDED_CHUNK_TAGWORD; chunk[0] = (Val)(Vunt)new_chunk; return PTR_CAST( Val, new_chunk ); // Done! } #endif break; case RO_VECTOR_HEADER_BTAG: case RW_VECTOR_HEADER_BTAG: // len_in_words = 2; // sib = ag1->sib[ RO_POINTERS_SIB ]; break; // Fall through to generic-case code. case RW_VECTOR_DATA_BTAG: // len_in_words = GET_LENGTH_IN_WORDS_FROM_TAGWORD( tagword ); // sib = ag1->sib[ RW_POINTERS_SIB ]; // The RW_POINTERS_SIB allows updates, which the RO_POINTERS_SIB does not. break; // Fall through to generic-case code. case FOUR_BYTE_ALIGNED_NONPOINTER_DATA_BTAG: // len_in_words = GET_LENGTH_IN_WORDS_FROM_TAGWORD( tagword ); // sib = ag1->sib[ NONPTR_DATA_SIB ]; break; // Fall through to generic-case code. case EIGHT_BYTE_ALIGNED_NONPOINTER_DATA_BTAG: // len_in_words = GET_LENGTH_IN_WORDS_FROM_TAGWORD( tagword ); // sib = ag1->sib[ NONPTR_DATA_SIB ]; // #ifdef ALIGN_FLOAT64S # ifdef CHECK_HEAP if (((Vunt)sib->tospace.first_free & WORD_BYTESIZE) == 0) { // *sib->tospace.first_free++ = (Val) 0; } # else sib->tospace.first_free = (Val*) (((Vunt)sib->tospace.first_free) | WORD_BYTESIZE); # endif #endif break; // Fall through to generic-case code. case WEAK_POINTER_OR_SUSPENSION_BTAG: // return forward_special_chunk ( ag1, chunk, tagword ); case FORWARDED_CHUNK_BTAG: // return PTR_CAST( Val, FOLLOW_FORWARDING_POINTER(chunk)); // We've already copied this one to agegroup1, so just return pointer to copy. default: log_if("bad chunk tag %d, chunk = %#x, tagword = %#x -- forward_agegroup0_chunk_to_agegroup1() in src/c/heapcleaner/heapclean-agegroup0.c", GET_BTAG_FROM_TAGWORD(tagword), chunk, tagword); log_if("forward_agegroup0_chunk_to_agegroup1 was called by %s", caller ? "process_task_heap_changelog" : "forward_to_agegroup1_if_in_agegroup0"); dump_task(task,"forward_agegroup0_chunk_to_agegroup1/default"); die ("bad chunk tag %d, chunk = %#x, tagword = %#x -- forward_agegroup0_chunk_to_agegroup1() in src/c/heapcleaner/heapclean-agegroup0.c", GET_BTAG_FROM_TAGWORD(tagword), chunk, tagword); exit(1); // Cannot execute -- just to quiet gcc -Wall. } // Make an agegroup1 copy of the chunk // in the appropriate agegroup1 sib (buffer): // new_chunk = sib->tospace.first_free; // Figure out where copy will be located. sib->tospace.first_free += (len_in_words + 1); // Allocate space needed by the copy. *new_chunk++ = tagword; // Install tagword at start of copy. (Note that 'sib' cannot be RO_CONSCELL_SIB, we handled that case above.) ASSERT( sib->tospace.first_free <= sib->tospace.limit ); COPYLOOP(chunk, new_chunk, len_in_words); // Copy over the rest of the chunk. // COPYLOOP def in src/c/heapcleaner/copy-loop.h // Set up the forwarding pointer in the original // to the copy and return the new chunk: // chunk[-1] = FORWARDED_CHUNK_TAGWORD; chunk[ 0] = (Val) (Vunt) new_chunk; return PTR_CAST( Val, new_chunk ); } // fun forward_agegroup0_chunk_to_agegroup1
void TestLevel::update(){ if (Menu::isNewLevel()) { float pixelDensityX = (float)Global::FbWidth / Global::ScreenWidth; levelTitle = TextPtr(new Text("Level2", glm::vec4(0, 0, 0, 1), glm::vec3(0, 0, 0), "FourPixel", 75)); levelTitle->setPosition(glm::vec3(0 - levelTitle->getTextWidth()/2.0/pixelDensityX, 0, 0)); PTR_CAST(TextRender, RenderEngine::getRenderElement("text"))->addText(levelTitle); Menu::setNewLevel(false); } if(debugPlayer->isActive()){ ASSERT(getCamera("Camera1") != getCamera("DebugCamera"), "Equal camera"); setMainCamera("DebugCamera"); getCamera("Camera1")->fix(); } else if(cinematicPlayer->isActive() && includeCinema){ ASSERT(getCamera("Camera1") != getCamera("CinematicCamera"), "Equal camera"); setMainCamera("CinematicCamera"); setCullingCamera("CinematicCamera"); player->setActive(false); } else{ player->setActive(true); setMainCamera("Camera1"); setCullingCamera("Camera1"); getCamera("Camera1")->fix(false, true, false); } timer += TimeManager::getDeltaTime() / 15.0; //l1->setDirection(glm::vec3(20.0 * sin(timer * 3.1), 5.0 * sin(timer * 3.4 + 5.0) + 30.0, 20.0 * sin(timer * 3.8 + 2.0))); //l1->setPosition(gridCenter + l1->getDirection()*1.0f); //l1->setViewMatrix(glm::lookAt( // gridCenter + l1->getDirection(), // gridCenter, glm::vec3(0, 1, 0))); if (!Menu::isActive()) { glm::vec4 titleColor = levelTitle->getColor(); if(titleColor.w > 0){ titleColor.w -= (float)TimeManager::getDeltaTime() * 0.3f; levelTitle->setColor(titleColor); } if (Menu::isNovice() && !cinematicPlayer->isActive()) { RenderEngine::removeRenderElement("text"); RenderEngine::addRenderElement("text", RenderElementPtr(new TextRender()), 10); glfwSetInputMode(Global::window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); RenderEngine::toggleElementsForMenu(); Menu::displayPage("UserGuide"); Menu::setNovice(false); } if(Menu::getCurrentPage() == "UserGuide") { player->setActive(false); } else { player->setActive(true); } } if(player->getPosition().y <= resetHeight){ LevelManager::resetLevel(); } sky->loadIdentity(); sky->scale(glm::vec3(-90.0f,-90.0f,-90.0f)); sky->translate(Director::getScene()->getCamera()->getEye()); }