示例#1
0
void ObjectRenderer::renderInstance(InstanceObject* instance,
                                    RenderList& outList) {
    const auto& atomic = instance->getAtomic();
    if (!atomic) {
        return;
    }

    // Only draw visible objects
    if (!instance->getVisible()) {
        return;
    }

    auto modelinfo = instance->getModelInfo<SimpleModelInfo>();

    // Handles times provided by TOBJ data
    const auto currentHour = m_world->getHour();
    if (modelinfo->timeOff < modelinfo->timeOn) {
        if (currentHour >= modelinfo->timeOff &&
            currentHour < modelinfo->timeOn)
            return;
    } else {
        if (currentHour >= modelinfo->timeOff ||
            currentHour < modelinfo->timeOn)
            return;
    }

    float mindist = glm::length(instance->getPosition() - m_camera.position) /
                    kDrawDistanceFactor;

    if (mindist > modelinfo->getLargestLodDistance()) {
        culled++;
        return;
    }

    if (modelinfo->isBigBuilding() &&
        mindist < modelinfo->getNearLodDistance() &&
        mindist < kMagicLODDistance) {
        auto related = modelinfo->related();
        if (!related || related->isLoaded()) {
            culled++;
            return;
        }
    }

    Atomic* distanceatomic =
        modelinfo->getDistanceAtomic(mindist / kDrawDistanceFactor);
    if (!distanceatomic) {
        return;
    }

    if (atomic->getGeometry() != distanceatomic->getGeometry()) {
        atomic->setGeometry(distanceatomic->getGeometry());
    }

    // Render the atomic the instance thinks it should be
    renderAtomic(atomic.get(), glm::mat4(), instance, outList);
}
示例#2
0
void
PDResource::SetDeleted(
	Boolean		inDeleted)
{

	// Validate pointers.

	ValidateThis_();

	if (inDeleted) {
		
		// We're being deleted.
		// Sanity check: Make sure we have a resource pointer.
		
		if (mRMResource == nil)
			return;
		
		// Cache the resource data in case we get undeleted.
		
		mDeletedResData = PackResData();
		ValidateHandle_(mDeletedResData);
		
		// Get the related resources list.
		
		LArray related(sizeof (RMResource*));
		GetRelatedResources(related);

		// Delete this resource from the map.
		
		mRMResource->DeleteResource();
		
		// Delete related resources from map.
		
		LFastArrayIterator iter(related);
		RMResource* rsrc;
		while (iter.Next(&rsrc)) {
			ValidateObject_(rsrc);
			rsrc->DeleteResource();
		}
		
		// Cut link to map's resource.
		
		mRMResource = nil;

	}
	else {
	
		// We're being restored. Unpack resource data
		// (unless this is the first time we've been created).
		
		if ((mDeletedResData != nil) && (mRMResource == nil))
			UnpackResData();
	
	}
}
示例#3
0
        /// extract the stack language from the CFG
        static void extract(
            cfg_cfg_type &cfg,
            nfa_nfa_type &nfa,
            bool partition,
            bool label_states
        ) throw() {
            char name_buff[1024] = {'\0'};

            std::map<variable_context, nfa_state_type> state_map;
            std::map<cfg_variable_type, context_set> contexts;

            cfg_variable_type L, R;
            cfg_symbol_string_type syms;
            cfg_generator_type cfg_vars(cfg.search((~L) --->* ~syms));

            // if we're not partitioning then the pre-emptively set the start
            // state to refer to the start variable of the grammar.
            if(!partition) {
                nfa_state_type start_state(nfa.get_start_state());
                cfg_variable_type start_var(cfg.get_start_variable());
                variable_context start_state_context;

                start_state_context.var = start_var;
                state_map[start_state_context] = start_state;

                if(label_states) {
                    nfa.set_name(start_state, cfg.get_name(start_var));
                }

                nfa.add_accept_state(start_state);
            }

            // go make all states
            for(; cfg_vars.match_next(); ) {
                for(unsigned i(0); i < syms.length(); ++i) {
                    if(!syms.at(i).is_variable()) {
                        continue;
                    }

                    R = syms.at(i);

                    variable_context ctx_var;
                    ctx_var.var = R;
                    if(partition) {
                        ctx_var.context = L;
                    }

                    nfa_state_type state;

                    // create the state
                    if(0U == state_map.count(ctx_var)) {
                        io::verbose("Added state for %s to %s\n", cfg.get_name(L), cfg.get_name(R));
                        state = nfa.add_state();
                        state_map[ctx_var] = state;

                        if(label_states) {
                            if(partition) {
                                sprintf(name_buff, "%s:%s", cfg.get_name(L), cfg.get_name(R));
                                nfa.set_name(state, name_buff);
                            } else {
                                nfa.set_name(state, cfg.get_name(R));
                            }
                        }

                    // we've already created this state
                    } else {
                        state = state_map[ctx_var];
                    }

                    contexts[L].insert(ctx_var);
                }
            }

            // go add all transitions
            for(cfg_vars.rewind(); cfg_vars.match_next(); ) {
                for(unsigned i(0); i < syms.length(); ++i) {
                    if(!syms.at(i).is_variable()) {
                        continue;
                    }

                    R = syms.at(i);

                    variable_context ctx_var;
                    ctx_var.var = R;
                    if(partition) {
                        ctx_var.context = L;
                    }

                    context_set &related(contexts[R]);
                    typename context_set::iterator it(related.begin());

                    for(; it != related.end(); ++it) {
                        io::verbose("Added transition from %s to %s\n", cfg.get_name(R), cfg.get_name(it->var));

                        nfa_state_type from_state(state_map[ctx_var]);
                        nfa_state_type to_state(state_map[*it]);

                        nfa.add_transition(
                            from_state,
                            label_states ? nfa.epsilon() : nfa.get_symbol(cfg.get_name(it->var)),
                            to_state
                        );
                    }
                }

                // there are transitions from L to R, but there are no transitions
                // from L to R to something else.
                context_set &related(contexts[L]);
                if(!partition && 0U != related.size()) {

                    variable_context ctx_var;
                    ctx_var.var = L;

                    nfa_state_type from_state(state_map[ctx_var]);
                    typename context_set::iterator it(related.begin());

                    if(0U != nfa.num_transitions(from_state)) {
                        continue;
                    }

                    for(; it != related.end(); ++it) {
                        io::verbose("Added transition from %s to %s\n", cfg.get_name(R), cfg.get_name(it->var));

                        nfa_state_type to_state(state_map[*it]);

                        nfa.add_transition(
                            from_state,
                            label_states ? nfa.epsilon() : nfa.get_symbol(cfg.get_name(it->var)),
                            to_state
                        );
                    }
                }
            }

            io::verbose("Adding in start state and transitions.\n");

            // if we are partitioning, then we need to use the start state
            // to signal that parsing is being started
            if(partition) {

                nfa_state_type start_state(nfa.get_start_state());
                cfg_variable_type start_var(cfg.get_start_variable());

                nfa.set_start_state(start_state);
                nfa.add_accept_state(start_state);

                if(label_states) {
                    sprintf(name_buff, ":%s", cfg.get_name(start_var));
                    nfa.set_name(start_state, name_buff);
                }

                std::set<variable_context> &related(contexts[start_var]);
                typename std::set<variable_context>::iterator it(related.begin());

                for(; it != related.end(); ++it) {
                    nfa_state_type to_state(state_map[*it]);
                    nfa.add_transition(
                        start_state,
                        label_states ? nfa.epsilon() : nfa.get_symbol(cfg.get_name(it->var)),
                        to_state
                    );
                }
            }
        }