Ejemplo n.º 1
0
bool Prop2D::clearChild( Prop2D *p ) {
    for(int i=0;i<elementof(children);i++) {
        if( children[i] ==p ) {
            for(int j=i;j<elementof(children)-1;j++){
                children[j] = children[j+1];
            }
            if(tracker) tracker->parent_rh->notifyChildCleared(this,p);
            children[children_num-1] = NULL;
            children_num --;
            return true;
        }
    }
    return false;
}
Ejemplo n.º 2
0
SoundSystem::SoundSystem()  : id_gen(1), remote_head(0), sys(0) {
#ifdef USE_FMOD    
	FMOD_RESULT r;
	r = FMOD_System_Create(&sys);
	FMOD_ERRCHECK(r);

	unsigned int version;
	r = FMOD_System_GetVersion(sys, &version);
	FMOD_ERRCHECK(r);
	if(version < FMOD_VERSION ){
		print("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
		return;
	}
	r = FMOD_System_Init( sys, 32, FMOD_INIT_NORMAL, NULL );
	FMOD_ERRCHECK(r);
#endif
#ifdef USE_UNTZ
	UNTZ::System::initialize( 44100, 512, 0 );
#endif
#ifdef USE_OPENAL
    if(alutInit(0,NULL)==AL_FALSE) {
        print("alutInit failed! error:%s", alutGetErrorString(alutGetError()));
        assert(false);
    } else {
        print("alutInit success!");
    }
#endif    
    for(int i=0;i<elementof(sounds);i++) sounds[i] = NULL;
}
Ejemplo n.º 3
0
Sound *SoundSystem::getById( int id ) {
    for(int i=0;i<elementof(sounds);i++) {
        if( sounds[i] && sounds[i]->id == id ) {
            return sounds[i];
        }
    }
    return NULL;
}
Ejemplo n.º 4
0
void SoundSystem::append( Sound *s ) {
    for(int i=0;i<elementof(sounds);i++) {
        if( sounds[i] == NULL ) {
            sounds[i] = s;
            return;
        }
    }
    assertmsg(false, "sound full");
}
Ejemplo n.º 5
0
int Group::pollAllProps(double dt ){
    last_dt = dt;
    int cnt=0;
    Prop *cur = prop_top;

    // poll
    Prop *to_clean[32*1024]; // 1ループにこの個数までclean
    int to_clean_cnt = 0;

    while(cur){
        cnt++;
        bool to_keep = cur->basePoll(dt);
        if(!to_keep) cur->to_clean = true;
        if( cur->to_clean ){
            if( to_clean_cnt < elementof(to_clean) ){
                if( cur->debug_id ) print("Debug: cleaning prop id:%d cnt:%d",cur->id, to_clean_cnt );
                to_clean[ to_clean_cnt ] = cur;
                to_clean_cnt ++;
            }
        } 
        cur = cur->next;
    }

    // clean 高速版
    //    if( to_clean_cnt > 0 ) print("top-p:%p clean_n:%d", prop_top, to_clean_cnt );

    for(int i=0;i<to_clean_cnt;i++){
        Prop *p = to_clean[i];
        if( p->debug_id ) print("deleting p:%p prev:%p next:%p", p, p->prev, p->next );

        if(p == prop_top ){
            prop_top = p->next;
        }
        if(p->prev ){
            p->prev->next = p->next;
        }
        if(p->next){
            p->next->prev = p->prev;
        }
        p->next = NULL;
        p->onDelete();
#ifdef __linux__
        std::map<int,Prop*>::iterator ii = idmap.find(p->id);
#else        
        std::unordered_map<int,Prop*>::iterator ii = idmap.find(p->id);
#endif        
        idmap.erase(ii);
        delete p;
    }
    last_poll_num = cnt;

    return cnt;
}
Ejemplo n.º 6
0
bool Moyai::insertEvent( double duration, void (*cbf)( void *argptr), void *argptr ) {
    for(int i=0;i<elementof(events);i++) {
        if( events[i].isUsed() == false ) {
            events[i].cb = cbf;
            events[i].duration = duration;
            events[i].argptr = argptr;
            return true;
        }
    }
    print("insertEvent: event full");
    return false;
}
Ejemplo n.º 7
0
int Moyai::poll(double dt){
    if( dt <0 || dt > 1 ){ print( "poll too slow or negative. dt:%f(sec)", dt ); }
    if(dt==0){
        dt = 0.0001;
    }
    int cnt = 0;
    for(int i=0;i<elementof(groups);i++){
        Group *g = groups[i];
        if(g && g->skip_poll == false ) cnt += g->pollAllProps(dt);
    }
    return cnt;
}
Ejemplo n.º 8
0
void Moyai::pollEvents( double dt ) {
    for(int i=0;i<elementof(events);i++) {
        if( events[i].isUsed() ) {
            //       print("ev[%d]: used, act:%f dur:%f", i, events[i].accum_time, events[i].duration );
            events[i].accum_time += dt;
            if( events[i].accum_time > events[i].duration ) {
                events[i].cb( events[i].argptr );
                events[i].duration = events[i].accum_time = 0;
                return;
            }
        }
    }
}
Ejemplo n.º 9
0
void Char::selectByCategory( Vec2 center, float dia, CATEGORY cat, Char *out[], int *outlen ) {
    Prop *hits[1024];
    int hitlen = elementof(hits);
    g_char_layer->selectCenterInside( center,dia, hits, &hitlen );
    int cnt=0;
    for(int i=0;i<hitlen;i++){
        Char*ch = (Char*) hits[i];
        if(ch->category == cat ){
            out[cnt++] = ch;
            if(cnt==*outlen)break;
        }
    }
    *outlen = cnt;
}
Ejemplo n.º 10
0
int MoyaiClient_OGL::render(){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );    
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	int cnt=0;
	for(int i=0;i<elementof(groups);i++){
		Group *g = groups[i];
		if( g && g->to_render ) {
			Layer *l = (Layer*) g;
			cnt += l->renderAllProps();
		}
	}

	glfwSwapBuffers();
	glFlush();
	return cnt;
}
Ejemplo n.º 11
0
void Field::generate() {
    globalInitShipData();

    int ship_h = elementof(g_ship_data);
    for(int y=0;y<ship_h;y++) {
        int ship_ind = ship_h-1-y;
        int l = strlen(g_ship_data[ship_ind]);
        for(int x=0;x<l;x++) {
            GROUNDTYPE gt = charToGT( g_ship_data[ship_ind][x] );
            Cell *c = get(x,y);
            if(!c)continue;
            c->gt = gt;
            c->subindex = 0;
            if(gt == GT_HATCH) {
                hatch_pos = Pos2(x,y);
            }
        }
        print("");
    }
}
Ejemplo n.º 12
0
void Moyai::clearEvents() {
    for(int i=0;i<elementof(events);i++) {
        events[i].duration = 0;
        events[i].cb = NULL;
    }
}
Ejemplo n.º 13
0
int Layer_D3D::renderAllProps(int layerIndex)
{
	assertmsg( viewport != nullptr, "no viewport in a layer id:%d setViewport missed?", id );

	m_layerIndex = layerIndex;

	if( viewport->dimension == DIMENSION_2D ) 
	{
		XMMATRIX orthoProjMatrix = XMMatrixOrthographicLH(viewport->scl.x, viewport->scl.y, 0.0f, 1000.0f);
		XMMATRIX identityMatrix = XMMatrixIdentity();
		CBufferMVP cbuffer(identityMatrix, orthoProjMatrix);

		D3D11_MAPPED_SUBRESOURCE map;
		g_context.m_pDeviceContext->Map(m_pMatrixConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
		memcpy(map.pData, &cbuffer, sizeof(CBufferMVP));
		g_context.m_pDeviceContext->Unmap(m_pMatrixConstantBuffer, 0);

		g_context.m_pDeviceContext->VSSetConstantBuffers(0, 1, &m_pMatrixConstantBuffer);
		g_context.m_pDeviceContext->PSSetConstantBuffers(0, 1, &m_pMatrixConstantBuffer);

		static SorterEntry tosort[1024*32];

		int cnt = 0;
		Prop *cur = prop_top;

		Vec2 minv, maxv;
		viewport->getMinMax(&minv, &maxv);

		while(cur)
		{
			Prop2D_D3D *cur2d = (Prop2D_D3D*)cur;

			assert( cur2d->dimension == viewport->dimension );

			// culling
			float camx=0,camy=0;
			if(camera)
			{
				camx = camera->loc.x;
				camy = camera->loc.y;
			}

			float scr_maxx = cur2d->loc.x - camx + cur2d->scl.x/2 + cur2d->max_rt_cache.x;
			float scr_minx = cur2d->loc.x - camx - cur2d->scl.x/2 + cur2d->min_lb_cache.x;
			float scr_maxy = cur2d->loc.y - camy + cur2d->scl.y/2 + cur2d->max_rt_cache.y;
			float scr_miny = cur2d->loc.y - camy - cur2d->scl.y/2 + cur2d->min_lb_cache.y;

			if( scr_maxx >= minv.x && scr_minx <= maxv.x && scr_maxy >= minv.y && scr_miny <= maxv.y )
			{
				tosort[cnt].val = cur2d->priority;
				tosort[cnt].ptr = cur2d;
				cnt++;

				if(cnt>= elementof(tosort))
				{
					print("WARNING: too many props in a layer : %d", cnt );
					break;
				}
			} 

			cur = cur->next;
		}

		quickSortF( tosort, 0, cnt-1 );
		for(int i=0;i<cnt;i++) 
		{
			Prop2D_D3D *p = (Prop2D_D3D*) tosort[i].ptr;
			if(p->visible)
			{
				p->render(camera);
			}
		}

		return sendDrawCalls();
	} 
	else // 3D
	{ 
		return 0;
	}
}