예제 #1
0
ATOM_CellData::ATOM_CellData (ATOM_Widget *parent, const ATOM_Rect2Di &rect, unsigned style, int id, ATOM_Widget::ShowState showState)
	: ATOM_Label (parent, rect, (style & ~ATOM_Widget::TitleBar) | ATOM_Widget::Control | ATOM_Widget::NonLayoutable, id, showState)
{
	ATOM_STACK_TRACE(ATOM_CellData::ATOM_CellData);

	ATOM_ASSERT(parent);
	ATOM_ASSERT(getRenderer());

	_cooldown = 0;
	_cooldownMax = 0;
	_cooldownImageId = ATOM_INVALID_IMAGEID;
	_selectImageId = ATOM_INVALID_IMAGEID;
	_frameImageId = ATOM_INVALID_IMAGEID;
	_subscriptImageId = ATOM_INVALID_IMAGEID;
	_frameOffset = 0;
	_oldPosition = rect.point;
	_clientDragging = false;
	_subscirptTextDirty = false;
	_subscriptText = ATOM_HARDREF(ATOM_Text)();
	_subscriptText->setFont (ATOM_GUIFont::getFontHandle(getFont()));
	_subscriptText->setCharMargin (ATOM_GUIFont::getFontCharMargin(getFont()));
	_subscriptText->setZValue (1.f);
	_subscriptText->setDisplayMode (ATOM_Text::DISPLAYMODE_2D);
	_subscriptRect = ATOM_Rect2Di(0,0,0,0);
	_subscriptTextPosition.x = _subscriptTextPosition.y = 0;
	setBorderMode (ATOM_Widget::Raise);

	resize (rect);

#if defined(USE_WIDGET_DEBUG_INFO)
	ATOM_Widget::registerWidgetDebugInfo (this);
#endif
}
예제 #2
0
bool ATOM_TerrainQuadtreeNode::initialize (ATOM_TerrainQuadtree *quadtree, ATOM_TerrainQuadtreeNode *parent, ATOM_TerrainPatch::PatchPosition position, ATOM_VertexArray *baseVertices)
{
  ATOM_STACK_TRACE(ATOM_TerrainQuadtreeNode::initialize);

  ATOM_ASSERT(!_parent);
  ATOM_ASSERT(!_patch);

  _parent = parent;
  _patch = ATOM_NEW(ATOM_TerrainPatch);

  if (!_patch->initialize (quadtree, _parent ? _parent->_patch : 0, position, baseVertices))
  {
    return false;
  }

  if (_patch->getStep () > 1)
  {
    for (unsigned i = 0; i < 4; ++i)
    {
      _children[i] = ATOM_NEW(ATOM_TerrainQuadtreeNode);
      if (!_children[i]->initialize (quadtree, this, (ATOM_TerrainPatch::PatchPosition)i, baseVertices))
      {
        return false;
      }
    }
  }

  return true;
}
예제 #3
0
void ATOM_SpatialCell::detachNode (ATOM_Node *node) 
{
  if (node)
  {
    NodeInfo *info = node->getCellNodeInfo ();
    ATOM_ASSERT(info);

    if (info->prev)
    {
      ATOM_ASSERT(info != _M_nodes);
      info->prev->next = info->next;
      if (info->next)
      {
        info->next->prev = info->prev;
      }
    }
    else
    {
      ATOM_ASSERT(info == _M_nodes);
      _M_nodes = info->next;

      if (_M_nodes)
      {
        _M_nodes->prev = 0;
      }
    }

    ATOM_DELETE(info);
    node->setCellNodeInfo (0);
  }
}
예제 #4
0
파일: button.cpp 프로젝트: gaoyakun/atom3d
ATOM_Button::ATOM_Button (ATOM_Widget *parent, const ATOM_Rect2Di &rect, unsigned style, int id, ATOM_Widget::ShowState showState)
:
ATOM_Label (parent, rect, (style & ~ATOM_Widget::TitleBar)|ATOM_Widget::Control, id, showState)
{
	ATOM_STACK_TRACE(ATOM_Button::ATOM_Button);

	ATOM_ASSERT(parent);
	ATOM_ASSERT(getRenderer());

	_mouseOn = false;

	_mouseEnterAnimator = NULL;
	_mouseLeaveAnimator = NULL;
	_currentAnimator = NULL;

	_clickSound = INVALID_AUDIOID;
	_hoverSound = INVALID_AUDIOID;

	setBorderMode (ATOM_Widget::Raise);

	resize (rect);

#if defined(USE_WIDGET_DEBUG_INFO)
	ATOM_Widget::registerWidgetDebugInfo (this);
#endif
}
예제 #5
0
ATOM_PropertyList::ATOM_PropertyList (ATOM_Widget *parent, const ATOM_Rect2Di &rect, unsigned style, int id, ATOM_Widget::ShowState showState)
: ATOM_ListView (parent, rect, style|ATOM_Widget::Control, id, showState)
{
	ATOM_STACK_TRACE(ATOM_PropertyList::ATOM_PropertyList);

	ATOM_ASSERT(parent);
	ATOM_ASSERT(getRenderer());

	setColumnCount(2);

#if defined(USE_WIDGET_DEBUG_INFO)
	ATOM_Widget::registerWidgetDebugInfo (this);
#endif
}
예제 #6
0
파일: edit.cpp 프로젝트: gaoyakun/atom3d
ATOM_Edit::ATOM_Edit (ATOM_Widget *parent, const ATOM_Rect2Di &rect, unsigned style, int id, ATOM_Widget::ShowState showState)
: ATOM_Widget (parent, rect, style|ATOM_Widget::Control|ATOM_Widget::ClipChildren, id, showState)
{
	ATOM_STACK_TRACE(ATOM_Edit::ATOM_Edit);

	ATOM_ASSERT(parent);
	ATOM_ASSERT(getRenderer());

	_text = ATOM_HARDREF(ATOM_Text) ();
	_text->setFont (ATOM_GUIFont::getFontHandle(getFont()));
	_text->setCharMargin (0);
	_text->setZValue (1.f);
	_text->setDisplayMode (ATOM_Text::DISPLAYMODE_2D);
	//_outlineColor.setRaw(0);
	_textPosition.x = 0;
	_textPosition.y = 0;
	_textDirty = false;

	_textDefault = ATOM_HARDREF(ATOM_Text) ();
	_textDefault->setFont (ATOM_GUIFont::getFontHandle(getFont()));
	_textDefault->setCharMargin (0);
	_textDefault->setZValue (1.f);
	_textDefault->setDisplayMode (ATOM_Text::DISPLAYMODE_2D);
	_fontDefualtColor = ATOM_ColorARGB(1.f, 1.f, 1.f, 1.f);
	_textDefaultPosition.x = 0;
	_textDefaultPosition.y = 0;

	_startPosition = 0;

	_cursor = 0;
	_cursorImageId = ATOM_IMAGEID_EDIT_CURSOR;
	_cursorOffset = 0;
	_cursorWidth = 2;
	_cursorPosition.x = 0;
	_cursorPosition.y = 0;
	_cusorNewPosition = _cusorOldPosition = _cursorPosition;
	_offsetX = 0;

	_editType = 0;
	_maxLength = 0;
	_frontImageId = 1;
	_selectStart = -1;
	resize (rect);

#if defined(USE_WIDGET_DEBUG_INFO)
	ATOM_Widget::registerWidgetDebugInfo (this);
#endif
}
예제 #7
0
파일: octree.cpp 프로젝트: gaoyakun/atom3d
void ATOM_Octree::initialize (float rootsize, float leafsize) 
{
  ATOM_ASSERT (rootsize >= leafsize && leafsize > 0);
  finalize ();

  _M_root_size = rootsize;
  _M_leaf_size = leafsize;

  unsigned n = 1;
  for (; rootsize >= leafsize * 2.f; leafsize *= 2.f, ++n)
    ;

  _M_chunks.resize (n);
  for (unsigned i = 0; i < n; ++i, rootsize *= 0.5f)
  {
    _M_chunks[i] = ATOM_NEW(ATOM_OctreeNodeChunk, this);
    _M_chunks[i]->setLevel (i);
    _M_chunks[i]->setNodeSize (rootsize);
    _M_chunks[i]->setNodeSizeLoosed (rootsize * 1.5f);
    _M_chunks[i]->setDimension (1 << i);
    if (i > 0) 
    {
      _M_chunks[i-1]->setNext (_M_chunks[i]);
      _M_chunks[i]->setPrev (_M_chunks[i-1]);
    }
  }
  _M_chunks.back ()->setNext (0);
}
예제 #8
0
파일: render.cpp 프로젝트: gaoyakun/atom3d
ATOM_AUTOREF(ATOM_RenderWindow) ATOM_Renderer::createRenderWindow(const char *title, int w, int h, bool naked, bool resizable, int multisample, ATOM_RenderWindow::ShowMode showMode, void* windowid, void *parentid, bool contentBackup, void *instance)
{
	ATOM_STACK_TRACE(ATOM_Renderer::createRenderWindow);
	if (!device)
	{
		return 0;
	}

	ATOM_HARDREF(ATOM_D3D9Window) window;
	ATOM_ASSERT(window);

	ATOM_RenderWindow::Hints hints;
	hints.accel = true;
	hints.bounds.first = w;
	hints.bounds.second = h;
	hints.resizable = resizable;
	hints.naked = naked;
	hints.bpp = 32;
	hints.samples = multisample;

	if (!window->open (device, title ? title : "", &hints, showMode, windowid, parentid, 0, instance))
	{
		return 0;
	}

	return window;
}
예제 #9
0
void ATOM_TerrainPatch::render (ATOM_RenderDevice *device)
{
	ATOM_STACK_TRACE(ATOM_TerrainPatch::render);

	ATOM_ASSERT(_quadtree);
	_geometry->draw (device, _quadtree->getPrimitiveType(), _quadtree->getPrimitiveCount(), 0);
}
예제 #10
0
ATOM_InstanceMesh::ATOM_InstanceMesh (ATOM_Node *node, ATOM_Mesh *mesh): _node(node), _mesh(mesh)
{
	ATOM_STACK_TRACE(ATOM_InstanceMesh::ATOM_InstanceMesh);

	ATOM_ASSERT(_mesh);
	_id = 0;
	_index = -1;
	_visible = true;
	_billboardNormal = mesh->billboardNormal;
	_billboardXAxis = mesh->billboardXAxis;
	_billboardCenter = mesh->billboardCenter;
	_worldMatrix = mesh->worldMatrix;
	_jointMapOk = false;
	_currentMapping = 0;
	_glareTexture = 0;
	_glareVelocity.set(0.f, 0.f, 0.f, 0.f);
	_glareRepeat.set(1.f, 1.f, 0.f, 0.f);
	_albedoTexture = _mesh->diffuseTexture;
	_lastAnimationFrame = -1.f;
	_updateFrameStamp = 0;
	_currentTrack = 0;
	_currentTrackFrame = -1.f;
	_diffuseColor = mesh->diffuseColor;
	_alpharef = mesh->alpharef;
	_shininess = mesh->shininess;
	_animationContext = 0;
}
예제 #11
0
void ATOM_SpatialCell::attachNode (ATOM_Node *node, unsigned updateStamp) 
{
  if (node)
  {
    ATOM_SpatialCell::NodeInfo *nodeInfo = node->getCellNodeInfo ();
    ATOM_ASSERT(!nodeInfo || nodeInfo->node == node);

    if (nodeInfo && nodeInfo->cell == this)
    {
      nodeInfo->lastUpdateStamp = updateStamp;
    }
    else
    {
      if (nodeInfo)
      {
        nodeInfo->cell->detachNode (node);
      }

      nodeInfo = ATOM_NEW(NodeInfo);
      nodeInfo->prev = 0;
      nodeInfo->next = _M_nodes;
      if (_M_nodes)
      {
        _M_nodes->prev = nodeInfo;
      }
      _M_nodes = nodeInfo;

      nodeInfo->cell = this;
      nodeInfo->node = node;
      nodeInfo->lastUpdateStamp = updateStamp;
      node->setCellNodeInfo (nodeInfo);
    }
  }
}
예제 #12
0
파일: octree.cpp 프로젝트: gaoyakun/atom3d
void ATOM_OctreeNodeChunk::freeNode (ATOM_OctreeNode *node) 
{
  if (node)
  {
    ATOM_ASSERT (node->getChunk () == this);
    freeNode (node->getPosition());
  }
}
예제 #13
0
파일: octree.cpp 프로젝트: gaoyakun/atom3d
ATOM_OctreeNode *ATOM_OctreeNode::getChild (Placement placement) const 
{
  ATOM_ASSERT (_M_chunk);
  if (_M_chunk->getNext())
  {
    return _M_chunk->getNext()->getNode (_M_chunk->getChildIndex(_M_position, placement));
  }
  return 0;
}
예제 #14
0
파일: octree.cpp 프로젝트: gaoyakun/atom3d
ATOM_OctreeNode *ATOM_OctreeNode::getOrCreateParent (void) const 
{
  ATOM_ASSERT (_M_chunk);
  if (_M_chunk->getPrev())
  {
    return _M_chunk->getPrev()->getOrCreateNode (_M_chunk->getParentIndex(_M_position));
  }
  return 0;
}
예제 #15
0
void ATOM_BaseImage::init (unsigned width, unsigned height, ATOM_PixelFormat format, const void* data, int mipcount) 
{
	ATOM_STACK_TRACE(ATOM_BaseImage::init);
	if ( width == 0 || height == 0)
	{
		fini ();
		return;
	}

	if ( !ATOM_IS_VALID_FORMAT(format))
	{
		ATOM_LOGGER::error ("[ATOM_BaseImage::init] Bad arguments: %d, %d, %d.\n", width, height, format);
		return;
	}

	unsigned buffersize = 0;
	const int blockdiv = 4;

	switch (format)
	{
	case ATOM_PIXEL_FORMAT_DXT1:
	case ATOM_PIXEL_FORMAT_DXT3:
	case ATOM_PIXEL_FORMAT_DXT5:
		{
			int blocksize = (format == ATOM_PIXEL_FORMAT_DXT1) ? 8 : 16;
			unsigned w = width;
			unsigned h = height;
			for (int i = 0; i < mipcount; ++i)
			{
				buffersize += ATOM_max2(blockdiv, w)/blockdiv * ATOM_max2(blockdiv, h)/blockdiv * blocksize;
				w = (w+1)>>1;
				h = (h+1)>>1;
			}
			break;
		}
	default:
		{
			unsigned bpp = ATOM_PIXEL_FORMAT(format).bpp / 8;
			buffersize = width * height * bpp;
			break;
		}
	}

	if (_M_contents && buffersize > _M_actual_size)
	{
		fini();
	}

	_M_buffersize = buffersize;

	if (!_M_contents)
	{
		_M_contents = ATOM_NEW_ARRAY(unsigned char, _M_buffersize);
		ATOM_ASSERT (_M_contents);
		_M_actual_size = _M_buffersize;
	}
예제 #16
0
void *ATOM_HWInstancingGeometry::addInstance (void)
{
	ATOM_STACK_TRACE(ATOM_HWInstancingGeometry::addInstance);

	//--- wangjian added ---//
	if( ATOM_RenderSettings::isUseInstancingStaticBuffer() )
		return 0;
	//----------------------//

	if (_instanceDataStreamAttrib == 0)
	{
		return 0;
	}

	int streamIndex = _numInstances / MAX_BATCH_COUNT;
	if (streamIndex != _lockedStreamIndex)
	{
		if (_lockedStreamIndex >= 0)
		{
			_instanceDataStreams[_lockedStreamIndex]->unlock ();
			_lockPtr = 0;
		}

		if (streamIndex >= _instanceDataStreams.size())
		{
			_instanceDataStreams.resize (streamIndex+1);
		}

		if (!_instanceDataStreams[streamIndex])
		{
			_instanceDataStreams[streamIndex] = ATOM_GetRenderDevice()->allocVertexArray (_instanceDataStreamAttrib, ATOM_USAGE_DYNAMIC, MAX_BATCH_COUNT);
			if (!_instanceDataStreams[streamIndex])
			{
				return 0;
			}
		}

		_lockPtr = _instanceDataStreams[streamIndex]->lock (ATOM_LOCK_WRITEONLY, 0, 0, true);
		if (!_lockPtr)
		{
			return 0;
		}

		_lockedStreamIndex = streamIndex;
	}

	ATOM_ASSERT(_lockPtr);
	char *data = (char*)_lockPtr;

	_lockPtr = data + _instanceDataSize;
	_numInstances++;

	return data;
}
예제 #17
0
float ATOM_TerrainPatch::getHeight (unsigned x, unsigned z) const
{
	unsigned patchSize = _quadtree->getPatchSize ();
	unsigned dimension = (patchSize - 1) * _step;
	ATOM_ASSERT (x >= _offsetX && x <= _offsetX + dimension);
	ATOM_ASSERT (z >= _offsetZ && z <= _offsetZ + dimension);
	unsigned startX = _offsetX + _step * ((x - _offsetX) / _step);
	unsigned startZ = _offsetZ + _step * ((z - _offsetZ) / _step);
	unsigned endX = startX == x ? startX : startX + _step;
	unsigned endZ = startZ == z ? startZ : startZ + _step;
	unsigned rootSize = _quadtree->getRootSize ();
	float lt_height = _quadtree->getHeightField()->getHeight(startX, startZ);
	float rt_height = _quadtree->getHeightField()->getHeight(endX, startZ);
	float lb_height = _quadtree->getHeightField()->getHeight(startX, endZ);
	float rb_height = _quadtree->getHeightField()->getHeight(endX, endZ);;
	float t1 = float(x - startX) / float(_step);
	float t2 = float(z - startZ) / float(_step);
	float h1 = lt_height + (rt_height - lt_height) * t1;
	float h2 = lb_height + (rb_height - lb_height) * t1;
	return h1 + (h2 - h1) * t2;
}
예제 #18
0
파일: octree.cpp 프로젝트: gaoyakun/atom3d
ATOM_Vector3f ATOM_OctreeNode::getMaxPoint (void) const 
{
  ATOM_ASSERT (_M_chunk);
  unsigned d = _M_chunk->getDimension ();
  float nodesize = _M_chunk->getNodeSize ();
  float half_worldsize = _M_chunk->getWorldSize () * 0.5f;
  NodeIndex px = (_M_position % d) + 1;
  NodeIndex py = ((_M_position / d) % d) + 1;
  NodeIndex pz = (_M_position / d / d) + 1;
  return ATOM_Vector3f (px * nodesize, py * nodesize, pz * nodesize)
         - ATOM_Vector3f (half_worldsize, half_worldsize, half_worldsize);
}
예제 #19
0
bool ATOM_D3DVertexArray::realize (void) {
  ATOM_STACK_TRACE(ATOM_D3DVertexArray::realize);
  if (!_M_vertexbuffer)
  {
    if (!_internalCreateVertexBuffer (_M_size_bytes))
    {
      ATOM_LOGGER::error ("%s() Create vertex buffer failed!\n", __FUNCTION__);
      return false;
    }
    ATOM_ASSERT (_M_vertexbuffer);
  }
  return true;
}
예제 #20
0
bool ATOM_TerrainPatch::initialize (ATOM_TerrainQuadtree *quadtree, ATOM_TerrainPatch *parent, PatchPosition position, ATOM_VertexArray *baseVertices)
{
	ATOM_STACK_TRACE(ATOM_TerrainPatch::initialize);

	ATOM_ASSERT(quadtree);

	unsigned patchSize = quadtree->getPatchSize ();
	unsigned rootSize = quadtree->getRootSize ();
	float scaleX = quadtree->getScaleX ();
	float scaleZ = quadtree->getScaleZ ();

	_mipLevel = parent ? parent->getMipLevel() + 1 : 0;
	unsigned step = ((rootSize - 1) / (patchSize - 1)) >> _mipLevel;
	unsigned interval = (patchSize - 1) * step;
	unsigned parentOffsetX = parent ? parent->getOffsetX() : 0;
	unsigned parentOffsetZ = parent ? parent->getOffsetZ() : 0;

	switch (position)
	{
	case ATOM_TerrainPatch::LeftTop:
		_offsetX = parentOffsetX;
		_offsetZ = parentOffsetZ;
		break;
	case ATOM_TerrainPatch::RightTop:
		_offsetX = parentOffsetX + interval;
		_offsetZ = parentOffsetZ;
		break;
	case ATOM_TerrainPatch::LeftBottom:
		_offsetX = parentOffsetX;
		_offsetZ = parentOffsetZ + interval;
		break;
	case ATOM_TerrainPatch::RightBottom:
		_offsetX = parentOffsetX + interval;
		_offsetZ = parentOffsetZ + interval;
		break;
	default:
		return false;
	}

	_position = position;
	_quadtree = quadtree;
	_step = step;
	_parent = parent;
	_maxError = computeMaxError ();

	setupVertices (computeSkirtLength (), baseVertices);
	_boxRadius = computeBoundingBox (_boundingBox);

	return true;
}
예제 #21
0
float ATOM_TerrainPatch::computeBoundingBox (ATOM_BBox &bbox) const
{
	ATOM_ASSERT(_quadtree);

	float maxHeight, minHeight;
	computeHeightBound (maxHeight, minHeight);

	float scaleX = _quadtree->getScaleX ();
	float scaleZ = _quadtree->getScaleZ ();
	ATOM_Vector3f minPoint(_offsetX * scaleX, minHeight, _offsetZ * scaleZ);
	ATOM_Vector3f maxPoint(_offsetX * scaleX + (_quadtree->getPatchSize() - 1) * _step * scaleX, maxHeight, _offsetZ * scaleZ + (_quadtree->getPatchSize() - 1) * _step * scaleZ);

	bbox.setMax (maxPoint);
	bbox.setMin (minPoint);

	return (maxPoint - minPoint).getLength() * 0.5f;
}
예제 #22
0
파일: decal.cpp 프로젝트: gaoyakun/atom3d
//--- wangjian added ---//
void ATOM_Decal::setupSortFlag(int queueid)
{
	//_material->autoSetActiveEffect (queueid);

	unsigned sf_ac = 0;
	unsigned sf_mt = 0;
	unsigned sf_matid = 0;

#if 0
	ULONGLONG matFlag = (ULONGLONG)_material->getActiveEffect();
	ULONGLONG miscFlag = 0;
	if( _texture )
		miscFlag = (ULONGLONG)_texture.get();
	ULONGLONG sf = ( matFlag << 32 ) + miscFlag;
#else

	//unsigned matFlag = (unsigned)_material->getActiveEffect();
	/*int effectid = getEffectIdEnd(ATOM_RenderScheme::getCurrentRenderScheme());
	ATOM_ASSERT(effectid!=-1);
	unsigned matFlag = (unsigned)_material->getCoreMaterial()->getEffect(effectid);
	matFlag <<= 16;
	matFlag /= 100000;
	matFlag *= 100000;
	unsigned miscFlag = 0;
	if( _texture )
	{
		miscFlag = (unsigned)_texture.get();
	}
	unsigned sf = matFlag + ( miscFlag & 0x0000ffff );*/

	int effectid = getEffectIdEnd(ATOM_RenderScheme::getCurrentRenderScheme());
	ATOM_ASSERT(effectid>=0);
	sf_ac = (unsigned)_material->getCoreMaterial()->getEffect(effectid);
	if( _texture )
	{
		sf_mt = (unsigned)_texture.get();
	}
#endif

	//setSortFlag(sf);
	setSortFlag(sf_ac,sf_mt,sf_matid);
}
예제 #23
0
int ATOM_ModelLoader::unlock (void)
{
	ATOM_STACK_TRACE(ATOM_ModelLoader::unlock);
	ATOM_ModelLockStruct *s = _model->getLockStruct ();
	ATOM_ASSERT(s);

	if (!s->wait)
	{
		s->wait = true;
		_model->unlock ();
		_model->initMaterials (true, true);
	}

	bool loadFailed = false;

	for (unsigned i = 0; i < s->depends.size(); ++i)
	{
		ATOM_LoadInterface::LoadingState state = s->depends[i]->getLoadingState();
		if (state == ATOM_LoadInterface::LS_LOADING)
		{
			return LOADINGSTAGE_TRYAGAIN;
		}
		else if (state != ATOM_LoadInterface::LS_LOADED)
		{
			ATOM_TextureLoadInterface *textureLoadInterface = dynamic_cast<ATOM_TextureLoadInterface*>(s->depends[i]);
			if (textureLoadInterface)
			{
				ATOM_LOGGER::error ("Texture <%s> load failed\n", textureLoadInterface->getFileName());
				textureLoadInterface->setTexture (ATOM_GetColorTexture (0xFFFFFFFF));
				textureLoadInterface->setLoadingState (ATOM_LoadInterface::LS_LOADED);
			}
			else
			{
				loadFailed = true;
			}
		}
	}

	s->depends.clear ();
	return loadFailed ? LOADINGSTAGE_NOTLOADED : LOADINGSTAGE_FINISH;
}
예제 #24
0
void ATOM_GameEntity::attachNode (ATOM_Node *node)
{
	ATOM_ASSERT(node);

	class AttachVisitor: public ATOM_Visitor
	{
	public:
		AttachVisitor (ATOM_GameEntity *entity): _entity (entity) {}
		ATOM_GameEntity *_entity;

	public:
		virtual void visit (ATOM_Node &node)
		{
			//ATOM_ASSERT(!node.getGameEntity());
			node.setGameEntity (_entity);
		}
	};

//	_node = node;

	AttachVisitor v(this);
	v.traverse (*node);
}
예제 #25
0
void ATOM_CellData::onPaint (ATOM_WidgetDrawClientEvent *event)
{
	ATOM_STACK_TRACE(ATOM_CellData::onPaint);

	ATOM_Rect2Di outRect(ATOM_Point2Di(0, 0), event->canvas->getSize());
	ATOM_Rect2Di inRect(_frameOffset, _frameOffset, outRect.size.w-_frameOffset*2, outRect.size.h-_frameOffset*2);

	bool inCD = (ATOM_INVALID_IMAGEID != _cooldownImageId) && _cooldownMax;

	if (_frameImageId != ATOM_INVALID_IMAGEID)
	{
		ATOM_GUIImage *image = getValidImage (_frameImageId);
		image->draw (event->state, event->canvas, outRect);
	}

	if (_clientImageId != ATOM_INVALID_IMAGEID)
	{
		ATOM_GUIImage *image = getValidImage (_clientImageId);
		if (!image)
		{
			image = ATOM_GUIImageList::getDefaultImageList().getImage (ATOM_IMAGEID_WINDOW_BKGROUND);
			ATOM_ASSERT(image);
		}
		if(_customColor)
		{
			image->draw (event->state, event->canvas, inRect, &_customColor);
		}
		else
		{
			image->draw (event->state, event->canvas, inRect);
		}

	}

	if (!_caption.empty())
	{
		if (_textDirty)
		{
			calcTextLayout ();
			_textDirty = false;
		}

		ATOM_GUICanvas::DrawTextInfo info;
		info.textObject = _text.get();
		info.textString = _text->getString();
		info.font = _text->getFont();
		info.x = _textPosition.x;
		info.y = _textPosition.y;
		info.shadowOffsetX = 0;
		info.shadowOffsetY = 0;
		info.textColor = getFontColor();
		info.outlineColor = _widgetFontOutLineColor;
		info.shadowColor = 0;
		info.underlineColor = _underlineColor;
		info.flags = ATOM_GUICanvas::DRAWTEXT_TEXTOBJECT;
		if(_widgetFontOutLineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_OUTLINE;
		}
		if(_underlineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_UNDERLINE;
		}
		event->canvas->drawTextEx(&info);
		//event->canvas->drawText (_text.get(), _textPosition.x, _textPosition.y, getFontColor());
	}
	//»æÖÆϱê×ÖÌå
	if (!_subscriptStr.empty())
	{
		if (_subscirptTextDirty)
		{
			calcSubscriptTextLayout();
			_subscirptTextDirty = false;
		}

		ATOM_GUICanvas::DrawTextInfo info;
		info.textObject = _subscriptText.get();
		info.textString = _subscriptText->getString();
		info.font = _subscriptText->getFont();
		info.x = _subscriptTextPosition.x;
		info.y = _subscriptTextPosition.y;
		info.shadowOffsetX = 0;
		info.shadowOffsetY = 0;
		info.textColor = getFontColor();
		info.outlineColor = _widgetFontOutLineColor;
		info.shadowColor = 0;
		info.underlineColor = _underlineColor;
		info.flags = ATOM_GUICanvas::DRAWTEXT_TEXTOBJECT;
		if(_widgetFontOutLineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_OUTLINE;
		}
		if(_underlineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_UNDERLINE;
		}
		event->canvas->drawTextEx(&info);
		//event->canvas->drawText (_text.get(), _textPosition.x, _textPosition.y, getFontColor());
	}
	//»æÖÆϱêͼƬ
	if(_subscriptImageId != ATOM_INVALID_IMAGEID)
	{
		ATOM_GUIImage *image = getValidImage (_subscriptImageId);
		if(!image)
		{
			image = ATOM_GUIImageList::getDefaultImageList().getImage(ATOM_IMAGEID_WINDOW_BKGROUND);
			ATOM_ASSERT(image);
		}
		image->draw(event->state,event->canvas,ATOM_Rect2Di(inRect.point.x+_subscriptRect.point.x,
			inRect.point.y+_subscriptRect.point.y,_subscriptRect.size.w,_subscriptRect.size.h));
	}

	if (_selectImageId != ATOM_INVALID_IMAGEID)
	{
#if 1
		ATOM_GUIImage *image = getValidImage (_selectImageId);
#else
		const ATOM_GUIImageList *imagelist = getValidImageList ();
		ATOM_GUIImage *image = imagelist->getImage (_selectImageId);
#endif
		if (!image)
		{
			image = ATOM_GUIImageList::getDefaultImageList().getImage (ATOM_IMAGEID_WINDOW_BKGROUND);
			ATOM_ASSERT(image);
		}
		image->draw (event->state, event->canvas, outRect);
	}

	//
	//bool inCD = (ATOM_INVALID_IMAGEID != _cooldownImageId) && _cooldownMax;

	//// »­CELL±³¾°
	//if(cell->_texture.pointer)
	//{
	//	unsigned color = inCD ? 0xFF808080 : 0xFFFFFFFF;
	//	canvas->drawTexturedRectEx(ATOM_Rect2Di(x*(xCellWidth+_xSpace), y*(yCellWidth+_ySpace), xCellWidth, yCellWidth), color, cell->_texture.pointer, cell->_region, false);
	//}
	//else if (_clientImageId != ATOM_INVALID_IMAGEID)
	//{
	//	imageDefault->draw (event->state, event->canvas, ATOM_Rect2Di(x*(xCellWidth+_xSpace), y*(yCellWidth+_ySpace), xCellWidth, yCellWidth));
	//}

	//if(cell->_text.pointer)
	//{
	//	const char* str = cell->_text->getString();
	//	if (strcmp (str, ""))
	//	{
	//		ATOM_FontHandle font = ATOM_GUIFont::getFontHandle (getFont());
	//		int charmargin = ATOM_GUIFont::getFontCharMargin (getFont());
	//		int charset = ATOM_GUIFont::getFontCharSet (getFont());
	//		ATOM_SetCharMargin (charmargin);
	//		int l, t, w, h;
	//		ATOM_CalcStringBounds (font, charset, str, strlen(str), &l, &t, &w, &h);
	//		canvas->drawText (cell->_text.pointer, x*(xCellWidth+_xSpace), y*(yCellWidth+_ySpace)-t, _fontColor);
	//	}
	//}

	// »­CD
	if(inCD)
	{
#if 1
		ATOM_GUIImage *image = getValidImage (_cooldownImageId);
#else
		ATOM_GUIImage* image = getValidImageList()->getImage (_cooldownImageId);
#endif
		if(image)
		{
			ATOM_Texture* texture = image->getTexture(WST_NORMAL);
			if(texture)
			{
				ATOM_CircleDrawer drawer(event->canvas, texture);
				drawer.DrawRemove(inRect, float(_cooldown)/float(_cooldownMax));
			}
		}
#if 0
		char buffer[256];
		sprintf (buffer, "%d", _cooldown);
		event->canvas->drawText (buffer, ATOM_GUIFont::getFontHandle(ATOM_GUIFont::getDefaultFont(10, 0)), 0, 0, 0xFFFFFFFF);
#endif
	}
}
예제 #26
0
const ATOM_BBox &ATOM_TerrainQuadtreeNode::getBoundingbox (void) const
{
  ATOM_ASSERT(_patch);

  return _patch->getBoundingbox ();
}
예제 #27
0
bool ATOM_D3DVertexArray::_internalCreateVertexBuffer (unsigned bytes) {
  ATOM_STACK_TRACE(ATOM_D3DVertexArray::_internalCreateVertexBuffer);
  if (_M_device && _M_device->isDeviceReady ())
  {
    ATOM_D3D9Device *device = (ATOM_D3D9Device*)_M_device;
    if (!device->getD3DDevice())
      return false;

    DWORD usage = D3DUSAGE_WRITEONLY;
	D3DPOOL pool = D3DPOOL_MANAGED;

    switch (_M_usage)
    {
    case ATOM_USAGE_STATIC:
      usage = D3DUSAGE_WRITEONLY;
      break;
    case ATOM_USAGE_DYNAMIC:
      usage = D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC;
	  pool = D3DPOOL_DEFAULT;
      break;
    case ATOM_USAGE_STOREONLY:
      return false;
      break;
    }

    HRESULT hr = device->getD3DDevice()->CreateVertexBuffer (bytes, usage, 0, pool, &_M_vertexbuffer, 0);

    if (FAILED(hr))
    {
		if (pool == D3DPOOL_DEFAULT && hr == D3DERR_OUTOFVIDEOMEMORY)
		{
			ATOM_LOGGER::error ("%s(%d) CreateVertexBuffer() failed because there is not enough video memory, evicting managed resources and try again...\n", __FUNCTION__, bytes);
			ATOM_CHECK_D3D_RESULT(device->getD3DDevice()->EvictManagedResources ());
			hr = device->getD3DDevice()->CreateVertexBuffer (bytes, usage, 0, pool, &_M_vertexbuffer, 0);
			if (FAILED(hr))
			{
				ATOM_LOGGER::error ("CreateVertexBuffer() still failed!\n");
				ATOM_CHECK_D3D_RESULT(hr);
				return false;
			}
		}
		else
		{
			ATOM_LOGGER::error ("%s(%d) CreateVertexBuffer() failed!\n", __FUNCTION__, bytes);
			ATOM_CHECK_D3D_RESULT(hr);
			return false;
		}

		return false;
    }

    ATOM_ASSERT (_M_vertexbuffer);
	_M_locked = 0;

	if (getRenderDevice()->isContentBackupEnabled())
	{
		_preservedContent = ATOM_MALLOC(bytes);
	}

    return true;
  }

  return false;
}
예제 #28
0
파일: edit.cpp 프로젝트: gaoyakun/atom3d
void ATOM_Edit::onPaint (ATOM_WidgetDrawClientEvent *event)
{
	ATOM_STACK_TRACE(ATOM_Edit::onPaint);

	ATOM_GUICanvas* canvas = event->canvas;
	ATOM_WidgetState state = event->state;

	if (_textDirty)
	{
		calcTextLayout ();
		_textDirty = false;
	}

	callParentHandler (event);
	//render select image
	// 绘制前景
	if(_cusorOldPosition != _cusorNewPosition)
	{
		ATOM_GUIImage *image = getValidImage (_frontImageId);
		ATOM_ASSERT(image);
		if(_cursorPosition.x - _cusorOldPosition.x > 0)
		{
			image->draw (event->state, event->canvas, ATOM_Rect2Di(_cusorOldPosition.x, _cursorPosition.y, _cursorPosition.x - _cusorOldPosition.x, _clientRect.size.h));
		}
		else
			image->draw (event->state, event->canvas, ATOM_Rect2Di( _cursorPosition.x , _cursorPosition.y, _cusorOldPosition.x - _cursorPosition.x, _clientRect.size.h));
	}
	// render text
	const char *text = _text->getString();
	if (strcmp (text, ""))
	{
		if(_widgetFontOutLineColor.getByteA())
		{
			canvas->drawTextOutline (_text.get(), _textPosition.x, _textPosition.y, getFontColor(), _widgetFontOutLineColor);
		}
		else
		{
			canvas->drawText (_text.get(), _textPosition.x, _textPosition.y, getFontColor());
		}
	}

	// render cursor
	if(0 == (EDITTYPE_READONLY & _editType))
	{	// 只读的时候,不显示光标
		if (_cursorImageId != ATOM_INVALID_IMAGEID)
		{
			if((getRenderer()->getFocus() == this) && (ATOM_APP->getFrameStamp().currentTick % 1000 < 500))
			{
#if 1
				ATOM_GUIImage *image = getValidImage (_cursorImageId);
#else
				const ATOM_GUIImageList *imagelist = getValidImageList ();
				ATOM_GUIImage *image = imagelist->getImage (_cursorImageId);
#endif
				if (!image)
				{
					image = ATOM_GUIImageList::getDefaultImageList().getImage (ATOM_IMAGEID_WINDOW_BKGROUND);
					ATOM_ASSERT(image);
				}

				image->draw (event->state, event->canvas, ATOM_Rect2Di(_cursorPosition.x, _cursorPosition.y, _cursorWidth, _clientRect.size.h));
			}
		}
	}

	// render default text
	if(0 == (EDITTYPE_READONLY & _editType))
	{	// 只读的时候,不显示默认字体
		if((getRenderer()->getFocus() != this) && !strcmp (_text->getString(), ""))
		{
			const char *textDefault = _textDefault->getString();
			if (strcmp (textDefault, ""))
			{
				if(_widgetFontOutLineColor.getByteA())
				{
					canvas->drawTextOutline (_textDefault.get(), _textDefaultPosition.x, _textDefaultPosition.y, _fontDefualtColor, _widgetFontOutLineColor);
				}
				else
				{
					canvas->drawText (_textDefault.get(), _textDefaultPosition.x, _textDefaultPosition.y, _fontDefualtColor);
				}
			}
		}
	}
}
예제 #29
0
bool ATOM_HWInstancingGeometry::draw (ATOM_RenderDevice *device, int type, int prim_count, int offset)
{
	ATOM_STACK_TRACE(ATOM_HWInstancingGeometry::draw);

	if (!_enableInstancing)
	{
		return ATOM_InterleavedStreamGeometry::draw (device, type, prim_count, offset);
	}

	if (_lockPtr)
	{
		_instanceDataStreams[_lockedStreamIndex]->unlock ();
		_lockedStreamIndex = -1;
		_lockPtr = 0;
	}

	if (_numInstances && _stream && _indices)
	{
		if (!_instancedVertexDecl)
		{
			createVertexDecl ();
		}

		if (_instancedVertexDecl)
		{
			device->setStreamSource (0, _stream.get());

			//--- wangjian modified ---//
#if 0
			if (_numInstances && _instanceDataStreams.size() > 0)
			{
				unsigned rem = _numInstances;
				unsigned stream = 0;
				device->setVertexDecl (_instancedVertexDecl);
				while (rem)
				{
					if (_instanceDataStreams[stream])
					{
						unsigned count = (rem > MAX_BATCH_COUNT) ? MAX_BATCH_COUNT : rem;
						device->setStreamSourceFreq (0, ATOM_STREAMSOURCE_INDEXEDDATA|count);
						device->setStreamSource (1, _instanceDataStreams[stream].get());
						device->setStreamSourceFreq (1, ATOM_STREAMSOURCE_INSTANCEDATA|1);
						device->renderStreamsIndexed(_indices.get(), type, prim_count, offset);
						rem -= count;
					}
					++stream;
				}
				device->setStreamSourceFreq (0, 1);
				device->setStreamSourceFreq (1, 1);
			}
#else

			// use static instance buffer
			if( ATOM_RenderSettings::isUseInstancingStaticBuffer() )
			{
				if( !_instanceData_staticbuffer )
					createStaticInstanceBuffer();

				if( _instanceData_staticbuffer )
				{
					device->setVertexDecl (_instancedVertexDecl);
					ATOM_ASSERT( _numInstances <= ATOM_RenderSettings::getInstancingSBCountThreshold() );
					device->setStreamSourceFreq (0, ATOM_STREAMSOURCE_INDEXEDDATA|_numInstances);
					device->setStreamSource (1, _instanceData_staticbuffer.get());
					device->setStreamSourceFreq (1, ATOM_STREAMSOURCE_INSTANCEDATA|1);
					device->renderStreamsIndexed(_indices.get(), type, prim_count, offset);
				}
			}
			else
			{
				if (_instanceDataStreams.size() > 0)
				{
					unsigned rem = _numInstances;
					unsigned stream = 0;
					device->setVertexDecl (_instancedVertexDecl);
					while (rem)
					{
						if (_instanceDataStreams[stream])
						{
							unsigned count = (rem > MAX_BATCH_COUNT) ? MAX_BATCH_COUNT : rem;
							device->setStreamSourceFreq (0, ATOM_STREAMSOURCE_INDEXEDDATA|count);
							device->setStreamSource (1, _instanceDataStreams[stream].get());
							device->setStreamSourceFreq (1, ATOM_STREAMSOURCE_INSTANCEDATA|1);
							device->renderStreamsIndexed(_indices.get(), type, prim_count, offset);
							rem -= count;
						}
						++stream;
					}
						
				}
			}

			device->setStreamSourceFreq (0, 1);
			device->setStreamSourceFreq (1, 1);
			device->setStreamSource (0, 0);
			device->setStreamSource (1, 0);
#endif
			//---------------------------------------------------------------------//

		}

		_numInstances = 0;

		return true;
	}

	return false;
}
예제 #30
0
	Material*	MaterialManager::GetMaterial( char const* name )
	{
		ATOM_ASSERT(m_materials[name], "material does not exist");
		return m_materials[name];
	}