void zz_font_d3d::draw_text_prim_outline_simple (const zz_font_text& text_item)
{
	assert(!text_item.to_texture);

	zz_renderer_d3d * r = static_cast<zz_renderer_d3d*>(znzin->renderer);

	if (!text_item.use_sprite) { // begin sprite
		zz_assert(!r->sprite_began());
		r->begin_sprite(ZZ_SPRITE_ALPHABLEND, "draw_text_prim_outline_simple");
		// we assumes that identity matrix transform is the default
	}
	else {
		zz_assert(r->sprite_began());
	}

	zz_font_text item(text_item);

	// overwrite color with outline color
	item.color = font_color_outline;
	
	draw_text_prim_offset(item,	-.5f,	-.5f);
	draw_text_prim_offset(item,	.5f,	.5f);
	draw_text_prim_offset(item,	-.5f,	.5f);
	draw_text_prim_offset(item,	.5f,	-.5f);

	item.color = font_color;
	draw_text_prim_offset(item, 0, 0);

	if (!text_item.use_sprite) { // end sprite
		r->end_sprite();
	}
}
Example #2
0
void zz_manager::load (zz_node * node)
{
	zz_assert(znzin);
	zz_assert(node);

	// remove first
	exit_line.remove(node);

	if (!znzin->get_rs()->use_delayed_loading || (node->get_load_weight() == 0)) { // from zz_waiting_line::flush()
		// try loading
		if (node->load()) {
			return;
		}
	}
	entrance_line.push(node);
}
Example #3
0
bool zz_texture::set_path (const char * path_in)
{
	const char * last_path = file_name.get();

	zz_assert(path_in);
	zz_assertf(znzin->file_system.exist(path_in), "[%s] file not found\n", path_in);

	// not to rename old
	zz_assertf(file_name.get() == 0, "rename [%s] failed", file_name.get());

	// set path
	file_name.set(path_in);
	//file_name.set("etc/shadowover.dds");
	// request to open and delayed-load. autu-closed in renderer_d3d->download_texture()
#ifdef USE_VFS_THREAD_TEXTURE_LOADING
	file_handle = znzin->vfs_thread->open(path_in); // will be closed in destructor or download_texture()
#endif

	// set weight by file size
	// CAUTION: only for vfs_local or vfs_pkg
	const int average_filesize = 100000; // 100 KB
	const int load_byte_per_msec = 1000; // 1 KB

#if (1)
	int filesize = znzin->file_system.get_size(path_in);
	load_weight = 1 + filesize/load_byte_per_msec; // 1(minimum size) + 1ms/10000byte
#endif

	res.make_ready(); // Just setting path is enough to be loaded.

	return true;
}
Example #4
0
void zz_mesh_terrain::set_property2
	(
		float scale_in, // client to engine scale
		vec3 minmax[2], // minmax 
		int uv_type0, // uv type for map1
		int uv_type1, // uv type for map2
		int width, // width size of height_list. number of horizotal heights
		int numskip, // skipping vertex. if skipsize is 2, we skip 2 vertices every vertex for both horizontal and vertical.
		const float * height_list, // height value array list
		float mapsize, // lightmap size. ex) 16000
		float blocksize // one block unit in world
	)
{
	pmin = scale_in*minmax[0];
	pmax = scale_in*minmax[1];

	orig_x_ = pmin.x;
	orig_y_ = pmax.y;

	detail_level_ = (width - 1) / (numskip + 1); // number of faces
	assert(detail_level_);
	uv_type0_ = uv_type0;
	uv_type1_ = uv_type1;
	mapsize_ = mapsize*scale_in;
	blocksize_ = blocksize*scale_in;

	int num_heights = (detail_level_ + 1) * (detail_level_ + 1);
	
	if (height_list_) {
		zz_assert(num_heights < num_heights_);
	}
	else {
		height_list_ = zz_new float[num_heights];
		num_heights_ = num_heights;
	}

	if (numskip == 0) { // same size, just copy
		memcpy(height_list_, height_list, num_heights*sizeof(float));
		for (int i = 0; i < num_heights; ++i) {
			height_list_[i] *= scale_in;
		}
	}
	else {
		int x, y;
		int is = 0, it = 0;
		for (y = 0; y < width; y += (numskip+1)) {
			for (x = 0; x < width; x += (numskip+1)) {
				is = y*width + x;
				assert(is < (width*width));
				height_list_[it] = scale_in*height_list[is];
				++it;
			}
		}
		assert(it == num_heights_);
	}
}
Example #5
0
void	zz_bone::gather_collidable (std::vector<zz_visible *>& collidable_holder)
{
	zz_assert(0);

	if (children.size() == 0) return;	
	zz_visible * child_vis;
	for (child_it it = children.begin(), it_end = children.end(); it != it_end; ++it) {
		child_vis = static_cast<zz_visible*>(*it);
		child_vis->gather_collidable(collidable_holder);
	}
}
Example #6
0
void zz_manager::unload (zz_node * node)
{
	zz_assert(node);
	zz_assert(znzin);

	// remove first
	entrance_line.remove(node); // not entered yet, but have to kill

	if (!znzin->get_rs()->use_delayed_loading) { // from zz_waiting_line::flush()
		// try unloading
		if (node->unload_and_release()) {
			return;
		}
		zz_assert(0);
	}

	node->init_reuse();

	exit_line.push(node); // include release
}
void zz_font_d3d::draw_text_prim_offset (const zz_font_text& text_item, float offsetx, float offsety)
{
	zz_assert(!text_item.to_texture);
	zz_assert(text_item.msg.get());
	zz_assert(text_item.msg.size());
	zz_assert(_d3d_font);
	
	if (!_d3d_font)
		return;

	zz_renderer_d3d * r = (zz_renderer_d3d *)(znzin->renderer);

	assert(r->is_a(ZZ_RUNTIME_TYPE(zz_renderer_d3d)));

	LPD3DXSPRITE sprite = r->get_sprite();
	zz_assert(sprite);
	HRESULT hr;

	D3DXMATRIX saved_tm;
	D3DXMATRIX new_tm;

	zz_assert(r->sprite_began());

	r->flush_sprite();
	r->get_sprite_transform((float*)&saved_tm); // save tm

	// adjust offset
	new_tm = saved_tm;

	// assert not-zero-scale
	assert(saved_tm._11 != 0);
	assert(saved_tm._22 != 0);
	assert(saved_tm._33 != 0);

	// we does not support rotation
	assert(saved_tm._12 == 0);
	assert(saved_tm._13 == 0);
	assert(saved_tm._21 == 0);
	assert(saved_tm._23 == 0);
	assert(saved_tm._31 == 0);
	assert(saved_tm._32 == 0);
	new_tm._41 += offsetx * saved_tm._11;
	new_tm._42 += offsety * saved_tm._22;

	r->set_sprite_transform((float*)&new_tm);

	RECT rect = text_item.rect;
	if (FAILED(hr = _draw_text(
		sprite,
		text_item.msg.get(), -1,
		&rect, 
		text_item.format,
		text_item.color )))
	{
		ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr));
	}

	sprite->SetTransform(&saved_tm); // restore tm
}
// create rendertarget texture and surface
bool zz_font_texture_d3d::restore_device_objects ()
{
	if (tex_height <= 0) return true;
	if (tex_width <= 0) return true;


	if (!znzin) return true;
	if (!znzin->renderer) return true;

	zz_renderer_d3d * r = static_cast<zz_renderer_d3d*>(znzin->renderer);
	if (!r->is_a(ZZ_RUNTIME_TYPE(zz_renderer_d3d))) return false;

	_device = r->get_device();
	if (!_device) return true;

	HRESULT hr;

	// create rendertarget texture
	if (FAILED(hr = _device->CreateTexture(
		tex_width, tex_height, 1, // level
		D3DUSAGE_RENDERTARGET,
		D3DFMT_A8R8G8B8,
		D3DPOOL_DEFAULT, // rendertarget must set this to D3DPOOL_DEFAULT
		&_texture, NULL)))
	{
		zz_render_state * rs = znzin->get_rs();
		if (rs) {
			ZZ_LOG("font_texture_d3d: createtexture(%dx%d)-(%dx%dx%d) failed(%s)\n",
				tex_width, tex_height,
				rs->buffer_width, rs->buffer_height, rs->buffer_depth,
				zz_renderer_d3d::get_hresult_string(hr));
		}
		else {
			ZZ_LOG("font_texture_d3d: createtexture() failed(%s). no rs\n", zz_renderer_d3d::get_hresult_string(hr));
		}
		return false;
	}

	// get texture surface
	if (FAILED(hr = _texture->GetSurfaceLevel(0, &_surface))) {
		zz_assert(0);
		return false;
	}

	return true;
}
Example #9
0
void zz_material_terrain::begin ()
{
	color_state = MS_NONE;
	alpha_state = MS_NONE;

	s_state.init();

	for (int i = 0; i < ZZ_MAX_TEXTURESTAGE; i++) {
		s_state.texture_address[i] = ZZ_TADDRESS_CLAMP;
	}
	s_state.cullmode = zz_render_state::ZZ_CULLMODE_CCW; // uses clockwise welding. see zz_mesh_tool.cpp

	zz_light * light = znzin->get_light();
	zz_assert(light);

	s_state.tfactor = zz_color(light->diffuse.r, light->diffuse.g, light->diffuse.b, light->diffuse.a);

	apply_shared_property(4);
}
Example #10
0
void zz_material_terrain_rough::begin ()
{
	color_state = MS_NONE;
	alpha_state = MS_NONE;

	s_state.init();

	for (int i = 0; i < ZZ_MAX_TEXTURESTAGE; i++) {
		s_state.texture_address[i] = ZZ_TADDRESS_CLAMP;
	}
	s_state.cullmode = zz_render_state::ZZ_CULLMODE_CCW; // uses clockwise welding. see zz_mesh_tool.cpp

	zz_light * light = znzin->get_light();
	zz_assert(light);

	s_state.tfactor = zz_color(light->diffuse.r, light->diffuse.g, light->diffuse.b, light->diffuse.a);

	apply_shared_property(1);

	s_renderer->enable_alpha_test( true, 254, ZZ_CMP_LESSEQUAL );
	s_renderer->enable_alpha_blend(true, ZZ_BT_CUSTOM);
	s_renderer->set_blend_type(ZZ_BLEND_INVSRCALPHA, ZZ_BLEND_SRCALPHA, ZZ_BLENDOP_ADD);
}
Example #11
0
// destroy managed/systemmem/scratch pool objects
bool zz_texture::delete_device_objects ()
{
	if (!res.is_delete_device_objects()) { // skip default
		return true;
	}

	if (!res.get_created()) {
		zz_assert(handle == ZZ_HANDLE_NULL);
		return true;
	}

#ifdef LOG_TEXTURE
	ZZ_LOG("texture: destroy_texture1(%s-%dx%d, %d)\n",
		get_path(), get_width(), get_width(), handle);
#endif

	znzin->renderer->destroy_texture(this);

	res.make_uncreated();
	handle = ZZ_HANDLE_NULL;
	
	return true;
}
Example #12
0
void zz_texture::set_property (
	const char * path_in, int width_in, int height_in, bool is_dynamic_in, int miplevels_in,
	bool use_filter_in, zz_device_resource::zz_resource_pool pool_in,
	ZZ_FORMAT format_in,
	bool for_image_in)
{
	zz_assert(!res.get_created());

	//if (res.get_created()) {
	//	unbind_device(); // makes res.buffered = false
	//}

	// if dynamic, and then always use default pool.
	assert(!is_dynamic_in || (is_dynamic_in && (pool_in == zz_device_resource::ZZ_POOL_DEFAULT)));
	
	// if not support dynamic textures
	if (is_dynamic_in && !znzin->get_rs()->use_dynamic_textures) {
		is_dynamic_in = false;
		pool_in = zz_device_resource::ZZ_POOL_DEFAULT;
	}

	for_image = for_image_in; // usage for image texture

	res.set_dynamic(is_dynamic_in);
	res.set_pool(pool_in);
	width = width_in;
	height = height_in;
	load_weight = 1;
	miplevels = miplevels_in;
	use_filter = use_filter_in;
	format = format_in;
	if (path_in) {
		set_path(path_in);
	}
	return;
}
Example #13
0
// called after clear_text_texture
void zz_font_d3d::draw_text_prim (const zz_font_text& text_item)
{
	if (!text_item.msg.get()) return;

	size_t length;
	length = text_item.msg.size();

	if (length <= 0) return; // draw nothing
	
	assert(_d3d_font);
	if (!_d3d_font)
		return;
	
	zz_renderer_d3d * r = static_cast<zz_renderer_d3d*>(znzin->renderer);
	LPD3DXSPRITE sprite = r->get_sprite();
	assert(sprite);

	if (!text_item.use_sprite) { // begin sprite
		
		zz_assert(!r->sprite_began());
		r->begin_sprite(ZZ_SPRITE_ALPHABLEND, "draw_text_prim");  //조성현 2006 04 25 Text출력..
		// we assumes that identity matrix transform is the default
	   D3DXMATRIX mat, mat2;
	   D3DXMatrixIdentity(&mat2);
	   sprite->GetTransform(&mat);
	   
	   mat2._41 = mat._41;
	   mat2._42 = mat._42;
	   mat2._43 = mat._43;
	
	   sprite->SetTransform(&mat2);

	    
	}
	else {
		zz_assert(r->sprite_began());
	  
	}

	HRESULT hr;

	if (text_item.to_texture) { // render to texture stage
		r->enable_zbuffer(false);
		r->enable_zwrite(false);

		zz_rect new_rect;
		int width, height;
		width = text_item.rect.right - text_item.rect.left;
		height = text_item.rect.bottom - text_item.rect.top;
		SetRect(&new_rect, text_item.tex_rect.left, text_item.tex_rect.top,
			text_item.tex_rect.left + width, text_item.tex_rect.top + height);

		assert((text_item.tex_rect.top != 0) || (text_item.tex_rect.bottom != 0));

		//ZZ_LOG("font: draw_text_prim(%s), [%d, %d]\n", text_item.msg.get(),	text_item.tex_rect.top, text_item.tex_rect.top + height);
		//ZZ_LOG("font: draw_text_prim(%s), [%d, %d, %d, %d]\n",
		//	text_item.msg.get(),
		//	new_rect.left, new_rect.top, new_rect.right, new_rect.bottom);

		DWORD frontcolor = 0xFFFFFFFF;

		if (FAILED(hr = _draw_text(
			sprite,
			text_item.msg.get(), -1,
			&new_rect, 
			text_item.format,
			frontcolor )))
		{
			ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr));
		}
		
		// restore states
		r->enable_zbuffer(true);
		r->enable_zwrite(true);
	}
	else {
		RECT rect = text_item.rect;
		if (FAILED(hr = _draw_text(
			sprite,
			text_item.msg.get(), -1,
			&rect, 
			text_item.format,
			text_item.color )))
		{
			ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr));
		}
	}

	if (!text_item.use_sprite) { // end sprite
		r->end_sprite();
	}
}
Example #14
0
void zz_bone::insert_scene()
{
	zz_assert(0);
}
Example #15
0
zz_bone::~zz_bone(void)
{
	zz_assert(!get_onode());
}
Example #16
0
bool zz_vfs_pkg::open (const char * filename_in, const zz_vfs_mode mode)
{
	if(mode==ZZ_VFS_WRITE) return false;
	//ZZ_LOG("vfs_pkg:open(%s)\n", filename);
	//ZZ_PROFILER_INSTALL(vfs_pkg_open);
	zz_assert(filename_in);
	zz_assert(filename_in[0]);

	zz_slash_converter filename(filename_in);

	if (fp_) {
		close();
	}

	assert(!fp_);
	if (!pkg_system_) {
		ZZ_LOG("vfs_pkg: open(%s) failed. invalid pkg_system_.\n", filename.get());
		return false;
	}

	//ZZ_LOG("vfs_pkg: open(%s)\n", filename);
	VHANDLE fsystem = pkg_system_->get_filesystem();

//	switch (mode) {
//		case zz_vfs::ZZ_VFS_READ:
			fp_ = VOpenFile(filename, fsystem);

			zz_assertf( fp_, "vfs_pkg: open(%s) failed.", filename.get() );

			filename_.set(filename);
			//check if it is encrypted
			fp_->btEncrypted=0;
			//if(fp_->btFileType==0){
			size_t spt;
			spt = fp_->sFileName.find_last_of("/\\");
			std::string hashstring1 = fp_->sFileName.substr(spt+1, (fp_->sFileName.length()-spt));
			//OutputDebugString(hashstring1.c_str());
			unsigned long key = StrToHashKey(hashstring1.c_str());
			char crypttable[16];
			DWORD *EAX=reinterpret_cast<DWORD*>(crypttable);
			DWORD EDI=0;
			DWORD ECX = key;
			DWORD EDX = key+1;
			ECX = ECX*4+1;
			for(int i = 0; i < 4; i++)
			{
				EDI=ECX*EDX;
				*((DWORD*)EAX) = EDI;
				EAX++;
				ECX+=4;
				EDX++;
			}
			vfseek(fp_, 0, VFSEEK_END);
			long off_set = vftell(fp_);
			if(off_set>16)
			{
				off_set-=16;
				vfseek(fp_,off_set, VFSEEK_SET);
				char buffer[16];
				vfread(&buffer,1,16,fp_);
				if(buffer[0]==crypttable[0]){
					if(buffer[1]==crypttable[1]){
						if(buffer[2]==crypttable[2]){
							if(buffer[3]==crypttable[3]){
								if(buffer[4]==crypttable[4]){
									if(buffer[5]==crypttable[5]){
										if(buffer[6]==crypttable[6]){
											if(buffer[7]==crypttable[7]){
												if(buffer[8]==crypttable[8]){
													if(buffer[9]==crypttable[9]){
														if(buffer[10]==crypttable[10]){
															if(buffer[11]==crypttable[11]){
																if(buffer[12]==crypttable[12]){
																	if(buffer[13]==crypttable[13]){
																		if(buffer[14]==crypttable[14]){
																			if(buffer[15]==crypttable[15]){
																				fp_->btEncrypted=0x90;
																				fp_->lEndOff-=16;
																				//MessageBox(0,fp_->sFileName.c_str()," is encrypted",0);
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			vfseek(fp_,0, VFSEEK_SET);
//			break;
//		case zz_vfs::ZZ_VFS_WRITE:
			// not implemented yet!!!
//			break;
//	}
	
	if (!fp_) {
		return false;
	}
	return true;
}
Example #17
0
void zz_mesh_terrain::set_property
	(
		float scale_in, // client to engine scale
		float orig_x, // world origin position x 
		float orig_y, // world origin position y
		int detail_level, // detail level(=num faces per block). ex) 1, 2, 4, 8.... 
		int uv_type0, // uv type for map1
		int uv_type1, // uv type for map2
		int width, // width size of height_list. number of horizotal heights
		const float * height_list, // height value array list
		float mapsize, // lightmap size. ex) 16000
		float blocksize // one block unit in world
	)
{
	orig_x_ = orig_x*scale_in;
	orig_y_ = orig_y*scale_in;
	detail_level_ = detail_level;
	uv_type0_ = uv_type0;
	uv_type1_ = uv_type1;
	mapsize_ = mapsize*scale_in;
	blocksize_ = blocksize*scale_in;

	int num_heights = (detail_level+1)*(detail_level+1);
	
	if (height_list_) {
		zz_assert(num_heights == num_heights_);
	}
	else {
		height_list_ = zz_new float[num_heights];
		num_heights_ = num_heights;
	}

	if (num_heights == (width*width)) { // same size, just copy
		memcpy(height_list_, height_list, num_heights*sizeof(float));
		for (int i = 0; i < num_heights; ++i) {
			height_list_[i] *= scale_in;
		}
	}
	else {
		int x, y;
		int is = 0, it = 0;
		assert(detail_level < width);
		int skipsize = (width-1)/detail_level;
		for (y = 0; y < width; y += skipsize) {
			for (x = 0; x < width; x += skipsize) {
				is = y*width + x;
				assert(is < (width*width));
				height_list_[it] = scale_in*height_list[is];
				++it;
			}
		}
	}

	float minz, maxz;

	int i;
	maxz = minz = height_list_[0];
	for (i = 1; i < num_heights; ++i) {
		if (height_list_[i] < minz) {
			minz = height_list_[i];
		}
		if (height_list_[i] > maxz) {
			maxz = height_list_[i];
		}
	}

	pmin = vec3(orig_x_, orig_y_ - blocksize_, minz);
	pmax = vec3(orig_x_ + blocksize_, orig_y_, maxz);
}
Example #18
0
void zz_bone::link_child (zz_bone * bone_child)
{
	zz_assert(bone_child->get_num_children() == 0);
	zz_node::link_child(static_cast<zz_node*>(bone_child));
}
Example #19
0
void zz_bone::link_child (zz_dummy * dummy_child)
{
	zz_assert(dummy_child->get_num_children() == 0);
	zz_node::link_child(static_cast<zz_node*>(dummy_child));
}
Example #20
0
zz_dummy::~zz_dummy ()
{
	zz_assert(!get_onode());
}
Example #21
0
void zz_dummy::remove_scene()
{
	zz_assert(0);
}
Example #22
0
void zz_dummy::insert_scene()
{
	zz_assert(0);
}
Example #23
0
void zz_bone::remove_scene()
{
	zz_assert(0);
}