<commit_before>// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string.h>
#include <iostream>

#include "chrome/browser/thumbnail_store.h"

#include "base/time.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/gfx/jpeg_codec.h"
#include "base/path_service.h"
#include "base/ref_counted.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/ref_counted_util.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkPixelRef.h"

inline unsigned int diff(unsigned int a, unsigned int b) {
  return a>b ? a-b : b-a;
}

class ThumbnailStoreTest : public testing::Test {
 public:
  ThumbnailStoreTest() : score1_(.5, true, false),
    url1_("http://www.google.com"), url2_("http://www.elgoog.com") {
  }
  ~ThumbnailStoreTest() {
  }

 protected:
  void SetUp();

  void TearDown() {
    file_util::Delete(file_path_.AppendASCII(url1_.host()), false);
    file_util::Delete(file_path_.AppendASCII(url2_.host()), false);
  }

  // Compute the max difference over all pixels for each RGBA component.
  void PrintPixelDiff(SkBitmap* image_a, SkBitmap* image_b);

  // The directory where ThumbnailStore will store data.
  FilePath file_path_;

  SkBitmap image_;
  scoped_refptr<RefCountedBytes> jpeg_image_;
  ThumbnailScore score1_, score2_;
  GURL url1_, url2_;
  base::Time time_;
};

void ThumbnailStoreTest::SetUp() {
  if (!file_util::GetTempDir(&file_path_))
    FAIL();

  // Delete any old thumbnail files if they exist.
  file_util::Delete(file_path_.AppendASCII(url1_.host()), false);
  file_util::Delete(file_path_.AppendASCII(url2_.host()), false);

  // image is the original SkBitmap representing the thumbnail
  image_ = *(JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail)));

  SkAutoLockPixels thumbnail_lock(image_);
  jpeg_image_ = new RefCountedBytes;
  bool encoded = JPEGCodec::Encode(
      reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)),
      JPEGCodec::FORMAT_BGRA, image_.width(),
      image_.height(),
      static_cast<int>(image_.rowBytes()), 90,
      &(jpeg_image_->data));
}

void ThumbnailStoreTest::PrintPixelDiff(SkBitmap* image_a, SkBitmap* image_b) {
  // Compute the maximum difference in each of the RGBA components across all
  // pixels between the retrieved SkBitmap and the original.  These
  // differences should be small since encoding was done at 90% before
  // writing to disk.

  if (image_a->height() != image_b->height() ||
      image_b->width() != image_b->width() ||
      image_a->rowBytes() != image_b->rowBytes())
    return;

  SkAutoLockPixels lock_a(*image_a);
  SkAutoLockPixels lock_b(*image_b);

  int ppr = image_a->rowBytesAsPixels();
  unsigned int *a, *b;
  unsigned int maxv[4];
  memset(maxv, 0, sizeof(maxv));

  for (int nrows = image_a->height()-1; nrows >= 0; nrows--) {
    a = image_a->getAddr32(0, nrows);
    b = image_b->getAddr32(0, nrows);
    for (int i = 0; i < ppr; i += 4) {
      for (int j = 0; j < 4; j++) {
        maxv[j] = std::max(diff(*(a+i) >> (j<<3) & 0xff,
                                *(b+i) >> (j<<3) & 0xff),
                           maxv[j]);
      }
    }
  }

  std::cout << "Max diff btwn original and encoded image (b,g,r,a) = ("
            << maxv[0] << ","
            << maxv[1] << ","
            << maxv[2] << ","
            << maxv[3] << ")" << std::endl;
}

TEST_F(ThumbnailStoreTest, RetrieveFromCache) {
  RefCountedBytes* read_image = NULL;
  scoped_refptr<ThumbnailStore> store = new ThumbnailStore;

  store->file_path_ = file_path_;
  store->cache_.reset(new ThumbnailStore::Cache);
  store->cache_initialized_ = true;

  // Retrieve a thumbnail/score for a nonexistent page.

  EXPECT_FALSE(store->GetPageThumbnail(url2_, &read_image));

  // Store a thumbnail into the cache and retrieve it.

  EXPECT_TRUE(store->SetPageThumbnail(url1_, image_, score1_, false));
  EXPECT_TRUE(store->GetPageThumbnail(url1_, &read_image));
  EXPECT_TRUE(score1_.Equals((*store->cache_)[url1_].second));
  EXPECT_TRUE(read_image->data.size() == jpeg_image_->data.size());
  EXPECT_EQ(0, memcmp(&read_image->data[0], &jpeg_image_->data[0],
                      jpeg_image_->data.size()));

  read_image->Release();
}

TEST_F(ThumbnailStoreTest, RetrieveFromDisk) {
  scoped_refptr<RefCountedBytes> read_image = new RefCountedBytes;
  scoped_refptr<ThumbnailStore> store = new ThumbnailStore;

  store->file_path_ = file_path_;
  store->cache_.reset(new ThumbnailStore::Cache);
  store->cache_initialized_ = true;

  // Store a thumbnail onto the disk and retrieve it.

  EXPECT_TRUE(store->SetPageThumbnail(url1_, image_, score1_, false));
  EXPECT_TRUE(store->WriteThumbnailToDisk(url1_));
  EXPECT_TRUE(store->GetPageThumbnailFromDisk(
      file_path_.AppendASCII(url1_.host()), &url2_, read_image, &score2_));
  read_image->AddRef();
  EXPECT_TRUE(url1_ == url2_);
  EXPECT_TRUE(score1_.Equals(score2_));
  EXPECT_TRUE(read_image->data.size() == jpeg_image_->data.size());
  EXPECT_EQ(0, memcmp(&read_image->data[0], &jpeg_image_->data[0],
                      jpeg_image_->data.size()));
}
<commit_msg>Fix Mac compile bustage Review URL: http://codereview.chromium.org/119379<commit_after>// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string.h>
#include <iostream>

#include "chrome/browser/thumbnail_store.h"

#include "base/time.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/gfx/jpeg_codec.h"
#include "base/path_service.h"
#include "base/ref_counted.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/ref_counted_util.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkPixelRef.h"

inline unsigned int diff(unsigned int a, unsigned int b) {
  return a>b ? a-b : b-a;
}

class ThumbnailStoreTest : public testing::Test {
 public:
  ThumbnailStoreTest() : score1_(.5, true, false),
    url1_("http://www.google.com"), url2_("http://www.elgoog.com") {
  }
  ~ThumbnailStoreTest() {
  }

 protected:
  void SetUp();

  void TearDown() {
    file_util::Delete(file_path_.AppendASCII(url1_.host()), false);
    file_util::Delete(file_path_.AppendASCII(url2_.host()), false);
  }

  // Compute the max difference over all pixels for each RGBA component.
  void PrintPixelDiff(SkBitmap* image_a, SkBitmap* image_b);

  // The directory where ThumbnailStore will store data.
  FilePath file_path_;

  SkBitmap image_;
  scoped_refptr<RefCountedBytes> jpeg_image_;
  ThumbnailScore score1_, score2_;
  GURL url1_, url2_;
  base::Time time_;
};

void ThumbnailStoreTest::SetUp() {
  if (!file_util::GetTempDir(&file_path_))
    FAIL();

  // Delete any old thumbnail files if they exist.
  file_util::Delete(file_path_.AppendASCII(url1_.host()), false);
  file_util::Delete(file_path_.AppendASCII(url2_.host()), false);

  // image is the original SkBitmap representing the thumbnail
  image_ = *(JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail)));

  SkAutoLockPixels thumbnail_lock(image_);
  jpeg_image_ = new RefCountedBytes;
  JPEGCodec::Encode(
      reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)),
      JPEGCodec::FORMAT_BGRA, image_.width(),
      image_.height(),
      static_cast<int>(image_.rowBytes()), 90,
      &(jpeg_image_->data));
}

void ThumbnailStoreTest::PrintPixelDiff(SkBitmap* image_a, SkBitmap* image_b) {
  // Compute the maximum difference in each of the RGBA components across all
  // pixels between the retrieved SkBitmap and the original.  These
  // differences should be small since encoding was done at 90% before
  // writing to disk.

  if (image_a->height() != image_b->height() ||
      image_b->width() != image_b->width() ||
      image_a->rowBytes() != image_b->rowBytes())
    return;

  SkAutoLockPixels lock_a(*image_a);
  SkAutoLockPixels lock_b(*image_b);

  int ppr = image_a->rowBytesAsPixels();
  unsigned int *a, *b;
  unsigned int maxv[4];
  memset(maxv, 0, sizeof(maxv));

  for (int nrows = image_a->height()-1; nrows >= 0; nrows--) {
    a = image_a->getAddr32(0, nrows);
    b = image_b->getAddr32(0, nrows);
    for (int i = 0; i < ppr; i += 4) {
      for (int j = 0; j < 4; j++) {
        maxv[j] = std::max(diff(*(a+i) >> (j<<3) & 0xff,
                                *(b+i) >> (j<<3) & 0xff),
                           maxv[j]);
      }
    }
  }

  std::cout << "Max diff btwn original and encoded image (b,g,r,a) = ("
            << maxv[0] << ","
            << maxv[1] << ","
            << maxv[2] << ","
            << maxv[3] << ")" << std::endl;
}

TEST_F(ThumbnailStoreTest, RetrieveFromCache) {
  RefCountedBytes* read_image = NULL;
  scoped_refptr<ThumbnailStore> store = new ThumbnailStore;

  store->file_path_ = file_path_;
  store->cache_.reset(new ThumbnailStore::Cache);
  store->cache_initialized_ = true;

  // Retrieve a thumbnail/score for a nonexistent page.

  EXPECT_FALSE(store->GetPageThumbnail(url2_, &read_image));

  // Store a thumbnail into the cache and retrieve it.

  EXPECT_TRUE(store->SetPageThumbnail(url1_, image_, score1_, false));
  EXPECT_TRUE(store->GetPageThumbnail(url1_, &read_image));
  EXPECT_TRUE(score1_.Equals((*store->cache_)[url1_].second));
  EXPECT_TRUE(read_image->data.size() == jpeg_image_->data.size());
  EXPECT_EQ(0, memcmp(&read_image->data[0], &jpeg_image_->data[0],
                      jpeg_image_->data.size()));

  read_image->Release();
}

TEST_F(ThumbnailStoreTest, RetrieveFromDisk) {
  scoped_refptr<RefCountedBytes> read_image = new RefCountedBytes;
  scoped_refptr<ThumbnailStore> store = new ThumbnailStore;

  store->file_path_ = file_path_;
  store->cache_.reset(new ThumbnailStore::Cache);
  store->cache_initialized_ = true;

  // Store a thumbnail onto the disk and retrieve it.

  EXPECT_TRUE(store->SetPageThumbnail(url1_, image_, score1_, false));
  EXPECT_TRUE(store->WriteThumbnailToDisk(url1_));
  EXPECT_TRUE(store->GetPageThumbnailFromDisk(
      file_path_.AppendASCII(url1_.host()), &url2_, read_image, &score2_));
  read_image->AddRef();
  EXPECT_TRUE(url1_ == url2_);
  EXPECT_TRUE(score1_.Equals(score2_));
  EXPECT_TRUE(read_image->data.size() == jpeg_image_->data.size());
  EXPECT_EQ(0, memcmp(&read_image->data[0], &jpeg_image_->data[0],
                      jpeg_image_->data.size()));
}
<|endoftext|>


<commit_before>#include "stdafx.h"
#include "Warg_Server.h"

void game_server(const char *wargspy_address)
{
  ENetHost *server;
  ENetPeer *wargspy;
  Game_State game_state;
  std::vector<Chat_Message> chat_log;
  std::unique_ptr<Map> map;
  std::map<UID, Peer> peers;

  auto resource_manager = new Resource_Manager();
  auto scene = new Flat_Scene_Graph(resource_manager);

  {
    map = std::make_unique<Map>(Blades_Edge(*scene));
    for (int i = 0; i < 1; i++)
      add_dummy(game_state, *map, {1, i, 5});
  }

  {
    ENetAddress addr = { .host = ENET_HOST_ANY, .port = GAME_PORT };
    server = enet_host_create(&addr, 32, 2, 0, 0);
  }

  {
    ENetAddress addr = { .port = WARGSPY_PORT };
    enet_address_set_host(&addr, wargspy_address);
    wargspy = enet_host_connect(server, &addr, 2, 0);
  }

  {
    ENetEvent event;
    enet_host_service(server, &event, 5000);
    // > 0 && event.type == ENET_EVENT_TYPE_CONNECT);
  }

  {
    float64 current_time = 0.0;
    float64 last_time = get_real_time() - dt;
    float64 elapsed_time = 0.0;
    while (true)
    {
      const float64 time = get_real_time();
      elapsed_time = time - current_time;
      last_time = current_time;
      while (current_time + dt < last_time + elapsed_time)
      {
        current_time += dt;

        {
          uint8 byte = 1;
          ENetPacket *packet = enet_packet_create(&byte, 1, 0);
          enet_peer_send(wargspy, 0, packet);
        }

        {
          ENetEvent event;
          while (enet_host_service(server, &event, 0) > 0)
          {
            switch (event.type)
            {
              case ENET_EVENT_TYPE_CONNECT:
              {
                UID peer_id = uid();
                event.peer->data = (void *)peer_id;
                peers[peer_id].peer = event.peer;
                break;
              }
              case ENET_EVENT_TYPE_RECEIVE:
              {
                Buffer b;
                b.insert(event.packet->data, event.packet->dataLength);
                int32 message_type;
                deserialize(b, message_type);
                switch (message_type)
                {
                  case SPAWN_MESSAGE:
                  {
                    std::string name;
                    int32 team;
                    deserialize(b, name);
                    deserialize(b, team);
                    Peer &peer = peers[(UID)event.peer->data];
                    if (none_of(game_state.living_characters, [&](auto& lc) { return lc.id == peer.character; }))
                    {
                      UID character = add_char(game_state, *map, team, name);
                      peer.character = character;
                    }
                    break;
                  }
                  case MOVE_MESSAGE:
                  {
                    int m;
                    quat orientation;
                    UID target_id;
                    deserialize(b, m);
                    deserialize(b, orientation);
                    deserialize(b, target_id);
                    Input command;
                    command.number = 0;
                    command.orientation = orientation;
                    command.m = m;
                    Peer &peer = peers[(UID)event.peer->data];
                    UID character = peer.character;
                    peer.last_input = command;
                    auto t = find_if(game_state.character_targets, [&](auto &t) { return t.character == character; });
                    if (t != game_state.character_targets.end())
                      t->target = target_id;
                    else
                      game_state.character_targets.push_back({character, target_id});
                    break;
                  }
                  case CAST_MESSAGE:
                  {
                    UID target, spell;
                    deserialize(b, target);
                    deserialize(b, spell);
                    Peer &peer = peers[(UID)event.peer->data];
                    UID character = peer.character;
                    cast_spell(game_state, *scene, character, target, spell);
                    break;
                  }
                  case CHAT_MESSAGE:
                  {
                    std::string chat_message;
                    deserialize(b, chat_message);
                    Peer &peer = peers[(UID)event.peer->data];
                    auto character = find_if(game_state.characters, [&](auto &c) { return c.id == peer.character; });
                    Chat_Message cm;
                    if (character != game_state.characters.end())
                      cm.name = character->name;
                    else
                      cm.name = "Unknown";
                    cm.message = chat_message;

                    Buffer b;
                    serialize_(b, CHAT_MESSAGE_RELAY);
                    serialize_(b, cm.name);
                    serialize_(b, cm.message);
                    for (auto &p : peers)
                    {
                      ENetPacket *packet = enet_packet_create(b.data.data(), b.data.size(), ENET_PACKET_FLAG_RELIABLE);
                      enet_peer_send(p.second.peer, 0, packet);
                      enet_host_flush(server);
                    }
                  }
                }

                enet_packet_destroy(event.packet);
                break;
              }

              case ENET_EVENT_TYPE_DISCONNECT:
              {
                peers.erase((UID)event.peer->data);
                break;
              }
            }
          }
        }

        {
          std::map<UID, Input> inputs;
          for (auto &p : peers)
            inputs[p.second.character] = p.second.last_input;
          update_game(game_state, *map, *scene, inputs);
        }

        for (auto &p : peers)
        {
          Buffer b;
          serialize_(b, STATE_MESSAGE);
          serialize_(b, game_state);
          serialize_(b, p.second.character);

          ENetPacket *packet = enet_packet_create(b.data.data(), b.data.size(), ENET_PACKET_FLAG_UNSEQUENCED);
          enet_peer_send(p.second.peer, 0, packet);
          enet_host_flush(server);
        }
      }
      SDL_Delay(5);
    }
  }

  enet_host_destroy(server);
  delete scene;
  delete resource_manager;
}
<commit_msg>Add uid_of(peer) helper function to server code<commit_after>#include "stdafx.h"
#include "Warg_Server.h"

UID uid_of(const ENetPeer const *peer)
{
  return peer ? (UID)peer->data : 0;
}

void game_server(const char *wargspy_address)
{
  ENetHost *server;
  ENetPeer *wargspy;
  Game_State game_state;
  std::vector<Chat_Message> chat_log;
  std::unique_ptr<Map> map;
  std::map<UID, Peer> peers;

  auto resource_manager = new Resource_Manager();
  auto scene = new Flat_Scene_Graph(resource_manager);

  {
    map = std::make_unique<Map>(Blades_Edge(*scene));
    for (int i = 0; i < 1; i++)
      add_dummy(game_state, *map, {1, i, 5});
  }

  {
    ENetAddress addr = { .host = ENET_HOST_ANY, .port = GAME_PORT };
    server = enet_host_create(&addr, 32, 2, 0, 0);
  }

  {
    ENetAddress addr = { .port = WARGSPY_PORT };
    enet_address_set_host(&addr, wargspy_address);
    wargspy = enet_host_connect(server, &addr, 2, 0);
  }

  {
    ENetEvent event;
    enet_host_service(server, &event, 5000);
    // > 0 && event.type == ENET_EVENT_TYPE_CONNECT);
  }

  {
    float64 current_time = 0.0;
    float64 last_time = get_real_time() - dt;
    float64 elapsed_time = 0.0;
    while (true)
    {
      const float64 time = get_real_time();
      elapsed_time = time - current_time;
      last_time = current_time;
      while (current_time + dt < last_time + elapsed_time)
      {
        current_time += dt;

        {
          uint8 byte = 1;
          ENetPacket *packet = enet_packet_create(&byte, 1, 0);
          enet_peer_send(wargspy, 0, packet);
        }

        {
          ENetEvent event;
          while (enet_host_service(server, &event, 0) > 0)
          {
            switch (event.type)
            {
              case ENET_EVENT_TYPE_CONNECT:
              {
                UID peer_id = uid();
                event.peer->data = (void *)peer_id;
                peers[peer_id].peer = event.peer;
                break;
              }

              case ENET_EVENT_TYPE_RECEIVE:
              {
                Buffer b;
                b.insert(event.packet->data, event.packet->dataLength);
                int32 message_type;
                deserialize(b, message_type);
                switch (message_type)
                {
                  case SPAWN_MESSAGE:
                  {
                    std::string name;
                    int32 team;
                    deserialize(b, name);
                    deserialize(b, team);
                    Peer &peer = peers[uid_of(event.peer)];
                    if (none_of(game_state.living_characters, [&](auto& lc) { return lc.id == peer.character; }))
                    {
                      UID character = add_char(game_state, *map, team, name);
                      peer.character = character;
                    }
                    break;
                  }
                  case MOVE_MESSAGE:
                  {
                    int m;
                    quat orientation;
                    UID target_id;
                    deserialize(b, m);
                    deserialize(b, orientation);
                    deserialize(b, target_id);
                    Input command;
                    command.number = 0;
                    command.orientation = orientation;
                    command.m = m;
                    Peer &peer = peers[uid_of(event.peer)];
                    UID character = peer.character;
                    peer.last_input = command;
                    auto t = find_if(game_state.character_targets, [&](auto &t) { return t.character == character; });
                    if (t != game_state.character_targets.end())
                      t->target = target_id;
                    else
                      game_state.character_targets.push_back({character, target_id});
                    break;
                  }
                  case CAST_MESSAGE:
                  {
                    UID target, spell;
                    deserialize(b, target);
                    deserialize(b, spell);
                    Peer &peer = peers[uid_of(event.peer)];
                    UID character = peer.character;
                    cast_spell(game_state, *scene, character, target, spell);
                    break;
                  }
                  case CHAT_MESSAGE:
                  {
                    std::string chat_message;
                    deserialize(b, chat_message);
                    Peer &peer = peers[uid_of(event.peer)];
                    auto character = find_if(game_state.characters, [&](auto &c) { return c.id == peer.character; });
                    Chat_Message cm;
                    if (character != game_state.characters.end())
                      cm.name = character->name;
                    else
                      cm.name = "Unknown";
                    cm.message = chat_message;

                    Buffer b;
                    serialize_(b, CHAT_MESSAGE_RELAY);
                    serialize_(b, cm.name);
                    serialize_(b, cm.message);
                    for (auto &p : peers)
                    {
                      ENetPacket *packet = enet_packet_create(b.data.data(), b.data.size(), ENET_PACKET_FLAG_RELIABLE);
                      enet_peer_send(p.second.peer, 0, packet);
                    }
                  }
                }

                enet_packet_destroy(event.packet);
                break;
              }

              case ENET_EVENT_TYPE_DISCONNECT:
              {
                peers.erase(uid_of(event.peer));
                break;
              }
            }
          }
        }

        {
          std::map<UID, Input> inputs;
          for (auto &p : peers)
            inputs[p.second.character] = p.second.last_input;
          update_game(game_state, *map, *scene, inputs);
        }

        for (auto &p : peers)
        {
          Buffer b;
          serialize_(b, STATE_MESSAGE);
          serialize_(b, game_state);
          serialize_(b, p.second.character);

          ENetPacket *packet = enet_packet_create(b.data.data(), b.data.size(), ENET_PACKET_FLAG_UNSEQUENCED);
          enet_peer_send(p.second.peer, 0, packet);
        }
      }
      enet_host_flush(server);
      SDL_Delay(5);
    }
  }

  enet_host_destroy(server);
  delete scene;
  delete resource_manager;
}
<|endoftext|>


<commit_before>// TestOwnerUI.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Main.h"
#include "MainFrame.h"

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	CPaintManagerUI::SetInstance(hInstance);

// 	CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
// 	CPaintManagerUI::SetResourceZip(_T("skin.dat"));

	HRESULT Hr = ::CoInitialize(NULL);
	if( FAILED(Hr) ) return 0;

	CMainFrame duiFrame;
	duiFrame.Create(NULL, _T("WeChat"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE /*| WS_EX_TOPMOST*/);
	duiFrame.SetIcon(IDI_WE_CHAT);
	duiFrame.CenterWindow();
	duiFrame.ShowModal();

	::CoUninitialize();
	return 0;
}<commit_msg>新增聊天记录本地缓存，优化聊天界面<commit_after>// TestOwnerUI.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Main.h"
#include "MainFrame.h"

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	CPaintManagerUI::SetInstance(hInstance);

	CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
	CPaintManagerUI::SetResourceZip(_T("skin.dat"));

	HRESULT Hr = ::CoInitialize(NULL);
	if( FAILED(Hr) ) return 0;

	CMainFrame duiFrame;
	duiFrame.Create(NULL, _T("WeChat"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE /*| WS_EX_TOPMOST*/);
	duiFrame.SetIcon(IDI_WE_CHAT);
	duiFrame.CenterWindow();
	duiFrame.ShowModal();

	::CoUninitialize();
	return 0;
}<|endoftext|>


<commit_before>/*
   For more information, please see: http://software.sci.utah.edu

   The MIT License

   Copyright (c) 2009 Scientific Computing and Imaging Institute,
   University of Utah.

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   DEALINGS IN THE SOFTWARE.
*/

#include <Core/Persistent/PersistentSTL.h>

#include <Core/GeometryPrimitives/Tensor.h>
#include <Core/GeometryPrimitives/Vector.h>
#include <Core/Basis/Constant.h>
#include <Core/Basis/NoData.h>
#include <Core/Basis/TriLinearLgn.h>
#include <Core/Basis/CrvLinearLgn.h>
#include <Core/Datatypes/Legacy/Field/TriSurfMesh.h>
#include <Core/Datatypes/Legacy/Field/CurveMesh.h>
#include <Core/Datatypes/Legacy/Field/GenericField.h>

using namespace SCIRun;

//NoData
typedef NoDataBasis<double>                  NDBasis;

//Linear
typedef ConstantBasis<Tensor>                CFDTensorBasis;
typedef ConstantBasis<Vector>                CFDVectorBasis;
typedef ConstantBasis<double>                CFDdoubleBasis;
typedef ConstantBasis<float>                 CFDfloatBasis;
typedef ConstantBasis<int>                   CFDintBasis;
typedef ConstantBasis<long long>             CFDlonglongBasis;
typedef ConstantBasis<short>                 CFDshortBasis;
typedef ConstantBasis<char>                  CFDcharBasis;
typedef ConstantBasis<unsigned int>          CFDuintBasis;
typedef ConstantBasis<unsigned short>        CFDushortBasis;
typedef ConstantBasis<unsigned char>         CFDucharBasis;
typedef ConstantBasis<unsigned long>         CFDulongBasis;

//Linear
typedef TriLinearLgn<Tensor>                FDTensorBasis;
typedef TriLinearLgn<Vector>                FDVectorBasis;
typedef TriLinearLgn<double>                FDdoubleBasis;
typedef TriLinearLgn<float>                 FDfloatBasis;
typedef TriLinearLgn<int>                   FDintBasis;
typedef TriLinearLgn<long long>             FDlonglongBasis;
typedef TriLinearLgn<short>                 FDshortBasis;
typedef TriLinearLgn<char>                  FDcharBasis;
typedef TriLinearLgn<unsigned int>          FDuintBasis;
typedef TriLinearLgn<unsigned short>        FDushortBasis;
typedef TriLinearLgn<unsigned char>         FDucharBasis;
typedef TriLinearLgn<unsigned long>         FDulongBasis;

typedef TriSurfMesh<TriLinearLgn<Point> > TSMesh;

namespace SCIRun
{
template class TriSurfMesh<TriLinearLgn<Point> >;

//noData
template class GenericField<TSMesh, NDBasis, std::vector<double> >;

//Constant
template class GenericField<TSMesh, CFDTensorBasis, std::vector<Tensor> >;
template class GenericField<TSMesh, CFDVectorBasis, std::vector<Vector> >;
template class GenericField<TSMesh, CFDdoubleBasis, std::vector<double> >;
template class GenericField<TSMesh, CFDfloatBasis,  std::vector<float> >;
template class GenericField<TSMesh, CFDintBasis,    std::vector<int> >;
template class GenericField<TSMesh, CFDlonglongBasis,std::vector<long long> >;
template class GenericField<TSMesh, CFDshortBasis,  std::vector<short> >;
template class GenericField<TSMesh, CFDcharBasis,   std::vector<char> >;
template class GenericField<TSMesh, CFDuintBasis,   std::vector<unsigned int> >;
template class GenericField<TSMesh, CFDushortBasis, std::vector<unsigned short> >;
template class GenericField<TSMesh, CFDucharBasis,  std::vector<unsigned char> >;
template class GenericField<TSMesh, CFDulongBasis,  std::vector<unsigned long> >;

//Linear
template class GenericField<TSMesh, FDTensorBasis, std::vector<Tensor> >;
template class GenericField<TSMesh, FDVectorBasis, std::vector<Vector> >;
template class GenericField<TSMesh, FDdoubleBasis, std::vector<double> >;
template class GenericField<TSMesh, FDfloatBasis,  std::vector<float> >;
template class GenericField<TSMesh, FDintBasis,    std::vector<int> >;
template class GenericField<TSMesh, FDlonglongBasis,std::vector<long long> >;
template class GenericField<TSMesh, FDshortBasis,  std::vector<short> >;
template class GenericField<TSMesh, FDcharBasis,   std::vector<char> >;
template class GenericField<TSMesh, FDuintBasis,   std::vector<unsigned int> >;
template class GenericField<TSMesh, FDushortBasis, std::vector<unsigned short> >;
template class GenericField<TSMesh, FDucharBasis,  std::vector<unsigned char> >;
template class GenericField<TSMesh, FDulongBasis,  std::vector<unsigned long> >;
}

PersistentTypeID backwards_compat_TSM("TriSurfMesh", "Mesh",
  TSMesh::maker, TSMesh::maker);

PersistentTypeID
backwards_compat_TSFT("TriSurfField<Tensor>", "Field",
		      GenericField<TSMesh, FDTensorBasis,
		      std::vector<Tensor> >::maker,
		      GenericField<TSMesh, CFDTensorBasis,
		      std::vector<Tensor> >::maker);
PersistentTypeID
backwards_compat_TSFV("TriSurfField<Vector>", "Field",
		      GenericField<TSMesh, FDVectorBasis,
		      std::vector<Vector> >::maker,
		      GenericField<TSMesh, CFDVectorBasis,
		      std::vector<Vector> >::maker);
PersistentTypeID
backwards_compat_TSFd("TriSurfField<double>", "Field",
		      GenericField<TSMesh, FDdoubleBasis,
		      std::vector<double> >::maker,
		      GenericField<TSMesh, CFDdoubleBasis,
		      std::vector<double> >::maker);
PersistentTypeID
backwards_compat_TSFf("TriSurfField<float>", "Field",
		      GenericField<TSMesh, FDfloatBasis,
		      std::vector<float> >::maker,
		      GenericField<TSMesh, CFDfloatBasis,
		      std::vector<float> >::maker);
PersistentTypeID
backwards_compat_TSFi("TriSurfField<int>", "Field",
		      GenericField<TSMesh, FDintBasis,
		      std::vector<int> >::maker,
		      GenericField<TSMesh, CFDintBasis,
		      std::vector<int> >::maker);
PersistentTypeID
backwards_compat_TSFs("TriSurfField<short>", "Field",
		      GenericField<TSMesh, FDshortBasis,
		      std::vector<short> >::maker,
		      GenericField<TSMesh, CFDshortBasis,
		      std::vector<short> >::maker);
PersistentTypeID
backwards_compat_TSFc("TriSurfField<char>", "Field",
		      GenericField<TSMesh, FDcharBasis,
		      std::vector<char> >::maker,
		      GenericField<TSMesh, CFDcharBasis,
		      std::vector<char> >::maker);
PersistentTypeID
backwards_compat_TSFui("TriSurfField<unsigned_int>", "Field",
		       GenericField<TSMesh, FDuintBasis,
		       std::vector<unsigned int> >::maker,
		       GenericField<TSMesh, CFDuintBasis,
		       std::vector<unsigned int> >::maker);
PersistentTypeID
backwards_compat_TSFus("TriSurfField<unsigned_short>", "Field",
		       GenericField<TSMesh, FDushortBasis,
		       std::vector<unsigned short> >::maker,
		       GenericField<TSMesh, CFDushortBasis,
		       std::vector<unsigned short> >::maker);
PersistentTypeID
backwards_compat_TSFuc("TriSurfField<unsigned_char>", "Field",
		       GenericField<TSMesh, FDucharBasis,
		       std::vector<unsigned char> >::maker,
		       GenericField<TSMesh, CFDucharBasis,
		       std::vector<unsigned char> >::maker);
PersistentTypeID
backwards_compat_TSFul("TriSurfField<unsigned_long>", "Field",
		       GenericField<TSMesh, FDulongBasis,
		       std::vector<unsigned long> >::maker,
		       GenericField<TSMesh, CFDulongBasis,
		       std::vector<unsigned long> >::maker);

//Linear
typedef CrvLinearLgn<Tensor>                CrFDTensorBasis;
typedef CrvLinearLgn<Vector>                CrFDVectorBasis;
typedef CrvLinearLgn<double>                CrFDdoubleBasis;
typedef CrvLinearLgn<float>                 CrFDfloatBasis;
typedef CrvLinearLgn<int>                   CrFDintBasis;
typedef CrvLinearLgn<long long>             CrFDlonglongBasis;
typedef CrvLinearLgn<short>                 CrFDshortBasis;
typedef CrvLinearLgn<char>                  CrFDcharBasis;
typedef CrvLinearLgn<unsigned int>          CrFDuintBasis;
typedef CrvLinearLgn<unsigned short>        CrFDushortBasis;
typedef CrvLinearLgn<unsigned char>         CrFDucharBasis;
typedef CrvLinearLgn<unsigned long>         CrFDulongBasis;

typedef CurveMesh<CrvLinearLgn<Point> > CMesh;
PersistentTypeID backwards_compat_CM("CurveMesh", "Mesh",
				      CMesh::maker, CMesh::maker);
template class CurveMesh<CrvLinearLgn<Point> >;

//NoData
template class GenericField<CMesh, NDBasis,  std::vector<double> >;

//Constant
template class GenericField<CMesh, CFDTensorBasis, std::vector<Tensor> >;
template class GenericField<CMesh, CFDVectorBasis, std::vector<Vector> >;
template class GenericField<CMesh, CFDdoubleBasis, std::vector<double> >;
template class GenericField<CMesh, CFDfloatBasis,  std::vector<float> >;
template class GenericField<CMesh, CFDintBasis,    std::vector<int> >;
template class GenericField<CMesh, CFDlonglongBasis,std::vector<long long> >;
template class GenericField<CMesh, CFDshortBasis,  std::vector<short> >;
template class GenericField<CMesh, CFDcharBasis,   std::vector<char> >;
template class GenericField<CMesh, CFDuintBasis,   std::vector<unsigned int> >;
template class GenericField<CMesh, CFDushortBasis, std::vector<unsigned short> >;
template class GenericField<CMesh, CFDucharBasis,  std::vector<unsigned char> >;
template class GenericField<CMesh, CFDulongBasis,  std::vector<unsigned long> >;

//Linear
template class GenericField<CMesh, CrFDTensorBasis, std::vector<Tensor> >;
template class GenericField<CMesh, CrFDVectorBasis, std::vector<Vector> >;
template class GenericField<CMesh, CrFDdoubleBasis, std::vector<double> >;
template class GenericField<CMesh, CrFDfloatBasis,  std::vector<float> >;
template class GenericField<CMesh, CrFDintBasis,    std::vector<int> >;
template class GenericField<CMesh, CrFDlonglongBasis,std::vector<long long> >;
template class GenericField<CMesh, CrFDshortBasis,  std::vector<short> >;
template class GenericField<CMesh, CrFDcharBasis,   std::vector<char> >;
template class GenericField<CMesh, CrFDuintBasis,   std::vector<unsigned int> >;
template class GenericField<CMesh, CrFDushortBasis, std::vector<unsigned short> >;
template class GenericField<CMesh, CrFDucharBasis,  std::vector<unsigned char> >;
template class GenericField<CMesh, CrFDulongBasis,  std::vector<unsigned long> >;

PersistentTypeID
backwards_compat_CFT("CurveField<Tensor>", "Field",
		     GenericField<CMesh, CrFDTensorBasis,
		     std::vector<Tensor> >::maker,
		     GenericField<CMesh, CFDTensorBasis,
		     std::vector<Tensor> >::maker);
PersistentTypeID
backwards_compat_CFV("CurveField<Vector>", "Field",
		     GenericField<CMesh, CrFDVectorBasis,
		     std::vector<Vector> >::maker,
		     GenericField<CMesh, CFDVectorBasis,
		     std::vector<Vector> >::maker);
PersistentTypeID
backwards_compat_CFd("CurveField<double>", "Field",
		     GenericField<CMesh, CrFDdoubleBasis,
		     std::vector<double> >::maker,
		     GenericField<CMesh, CFDdoubleBasis,
		     std::vector<double> >::maker,
		     GenericField<CMesh, NDBasis,
		     std::vector<double> >::maker);
PersistentTypeID
backwards_compat_CFf("CurveField<float>", "Field",
		     GenericField<CMesh, CrFDfloatBasis,
		     std::vector<float> >::maker,
		     GenericField<CMesh, CFDfloatBasis,
		     std::vector<float> >::maker);
PersistentTypeID
backwards_compat_CFi("CurveField<int>", "Field",
		     GenericField<CMesh, CrFDintBasis,
		     std::vector<int> >::maker,
		     GenericField<CMesh, CFDintBasis,
		     std::vector<int> >::maker);
PersistentTypeID
backwards_compat_CFs("CurveField<short>", "Field",
		     GenericField<CMesh, CrFDshortBasis,
		     std::vector<short> >::maker,
		     GenericField<CMesh, CFDshortBasis,
		     std::vector<short> >::maker);
PersistentTypeID
backwards_compat_CFc("CurveField<char>", "Field",
		     GenericField<CMesh, CrFDcharBasis,
		     std::vector<char> >::maker,
		     GenericField<CMesh, CFDcharBasis,
		     std::vector<char> >::maker);
PersistentTypeID
backwards_compat_CFui("CurveField<unsigned_int>", "Field",
		      GenericField<CMesh, CrFDuintBasis,
		      std::vector<unsigned int> >::maker,
		      GenericField<CMesh, CFDuintBasis,
		      std::vector<unsigned int> >::maker);
PersistentTypeID
backwards_compat_CFus("CurveField<unsigned_short>", "Field",
		      GenericField<CMesh, CrFDushortBasis,
		      std::vector<unsigned short> >::maker,
		      GenericField<CMesh, CFDushortBasis,
		      std::vector<unsigned short> >::maker);
PersistentTypeID
backwards_compat_CFuc("CurveField<unsigned_char>", "Field",
		      GenericField<CMesh, CrFDucharBasis,
		      std::vector<unsigned char> >::maker,
		      GenericField<CMesh, CFDucharBasis,
		      std::vector<unsigned char> >::maker);
PersistentTypeID
backwards_compat_CFul("CurveField<unsigned_long>", "Field",
		      GenericField<CMesh, CrFDulongBasis,
		      std::vector<unsigned long> >::maker,
		      GenericField<CMesh, CFDulongBasis,
		      std::vector<unsigned long> >::maker);
<commit_msg>Clang fix<commit_after>/*
   For more information, please see: http://software.sci.utah.edu

   The MIT License

   Copyright (c) 2009 Scientific Computing and Imaging Institute,
   University of Utah.

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   DEALINGS IN THE SOFTWARE.
*/

#include <Core/Persistent/PersistentSTL.h>

#include <Core/GeometryPrimitives/Tensor.h>
#include <Core/GeometryPrimitives/Vector.h>
#include <Core/Basis/Constant.h>
#include <Core/Basis/NoData.h>
#include <Core/Basis/TriLinearLgn.h>
#include <Core/Basis/CrvLinearLgn.h>
#include <Core/Datatypes/Legacy/Field/TriSurfMesh.h>
#include <Core/Datatypes/Legacy/Field/CurveMesh.h>
#include <Core/Datatypes/Legacy/Field/GenericField.h>

using namespace SCIRun;

//NoData
typedef NoDataBasis<double>                  NDBasis;

//Linear
typedef ConstantBasis<Tensor>                CFDTensorBasis;
typedef ConstantBasis<Vector>                CFDVectorBasis;
typedef ConstantBasis<double>                CFDdoubleBasis;
typedef ConstantBasis<float>                 CFDfloatBasis;
typedef ConstantBasis<int>                   CFDintBasis;
typedef ConstantBasis<long long>             CFDlonglongBasis;
typedef ConstantBasis<short>                 CFDshortBasis;
typedef ConstantBasis<char>                  CFDcharBasis;
typedef ConstantBasis<unsigned int>          CFDuintBasis;
typedef ConstantBasis<unsigned short>        CFDushortBasis;
typedef ConstantBasis<unsigned char>         CFDucharBasis;
typedef ConstantBasis<unsigned long>         CFDulongBasis;

//Linear
typedef TriLinearLgn<Tensor>                FDTensorBasis;
typedef TriLinearLgn<Vector>                FDVectorBasis;
typedef TriLinearLgn<double>                FDdoubleBasis;
typedef TriLinearLgn<float>                 FDfloatBasis;
typedef TriLinearLgn<int>                   FDintBasis;
typedef TriLinearLgn<long long>             FDlonglongBasis;
typedef TriLinearLgn<short>                 FDshortBasis;
typedef TriLinearLgn<char>                  FDcharBasis;
typedef TriLinearLgn<unsigned int>          FDuintBasis;
typedef TriLinearLgn<unsigned short>        FDushortBasis;
typedef TriLinearLgn<unsigned char>         FDucharBasis;
typedef TriLinearLgn<unsigned long>         FDulongBasis;

typedef TriSurfMesh<TriLinearLgn<Point> > TSMesh;

namespace SCIRun
{
template class TriSurfMesh<TriLinearLgn<Point> >;

//noData
template class GenericField<TSMesh, NDBasis, std::vector<double> >;

//Constant
template class GenericField<TSMesh, CFDTensorBasis, std::vector<Tensor> >;
template class GenericField<TSMesh, CFDVectorBasis, std::vector<Vector> >;
template class GenericField<TSMesh, CFDdoubleBasis, std::vector<double> >;
template class GenericField<TSMesh, CFDfloatBasis,  std::vector<float> >;
template class GenericField<TSMesh, CFDintBasis,    std::vector<int> >;
template class GenericField<TSMesh, CFDlonglongBasis,std::vector<long long> >;
template class GenericField<TSMesh, CFDshortBasis,  std::vector<short> >;
template class GenericField<TSMesh, CFDcharBasis,   std::vector<char> >;
template class GenericField<TSMesh, CFDuintBasis,   std::vector<unsigned int> >;
template class GenericField<TSMesh, CFDushortBasis, std::vector<unsigned short> >;
template class GenericField<TSMesh, CFDucharBasis,  std::vector<unsigned char> >;
template class GenericField<TSMesh, CFDulongBasis,  std::vector<unsigned long> >;

//Linear
template class GenericField<TSMesh, FDTensorBasis, std::vector<Tensor> >;
template class GenericField<TSMesh, FDVectorBasis, std::vector<Vector> >;
template class GenericField<TSMesh, FDdoubleBasis, std::vector<double> >;
template class GenericField<TSMesh, FDfloatBasis,  std::vector<float> >;
template class GenericField<TSMesh, FDintBasis,    std::vector<int> >;
template class GenericField<TSMesh, FDlonglongBasis,std::vector<long long> >;
template class GenericField<TSMesh, FDshortBasis,  std::vector<short> >;
template class GenericField<TSMesh, FDcharBasis,   std::vector<char> >;
template class GenericField<TSMesh, FDuintBasis,   std::vector<unsigned int> >;
template class GenericField<TSMesh, FDushortBasis, std::vector<unsigned short> >;
template class GenericField<TSMesh, FDucharBasis,  std::vector<unsigned char> >;
template class GenericField<TSMesh, FDulongBasis,  std::vector<unsigned long> >;
}

PersistentTypeID backwards_compat_TSM("TriSurfMesh", "Mesh",
  TSMesh::maker, TSMesh::maker);

PersistentTypeID
backwards_compat_TSFT("TriSurfField<Tensor>", "Field",
		      GenericField<TSMesh, FDTensorBasis,
		      std::vector<Tensor> >::maker,
		      GenericField<TSMesh, CFDTensorBasis,
		      std::vector<Tensor> >::maker);
PersistentTypeID
backwards_compat_TSFV("TriSurfField<Vector>", "Field",
		      GenericField<TSMesh, FDVectorBasis,
		      std::vector<Vector> >::maker,
		      GenericField<TSMesh, CFDVectorBasis,
		      std::vector<Vector> >::maker);
PersistentTypeID
backwards_compat_TSFd("TriSurfField<double>", "Field",
		      GenericField<TSMesh, FDdoubleBasis,
		      std::vector<double> >::maker,
		      GenericField<TSMesh, CFDdoubleBasis,
		      std::vector<double> >::maker);
PersistentTypeID
backwards_compat_TSFf("TriSurfField<float>", "Field",
		      GenericField<TSMesh, FDfloatBasis,
		      std::vector<float> >::maker,
		      GenericField<TSMesh, CFDfloatBasis,
		      std::vector<float> >::maker);
PersistentTypeID
backwards_compat_TSFi("TriSurfField<int>", "Field",
		      GenericField<TSMesh, FDintBasis,
		      std::vector<int> >::maker,
		      GenericField<TSMesh, CFDintBasis,
		      std::vector<int> >::maker);
PersistentTypeID
backwards_compat_TSFs("TriSurfField<short>", "Field",
		      GenericField<TSMesh, FDshortBasis,
		      std::vector<short> >::maker,
		      GenericField<TSMesh, CFDshortBasis,
		      std::vector<short> >::maker);
PersistentTypeID
backwards_compat_TSFc("TriSurfField<char>", "Field",
		      GenericField<TSMesh, FDcharBasis,
		      std::vector<char> >::maker,
		      GenericField<TSMesh, CFDcharBasis,
		      std::vector<char> >::maker);
PersistentTypeID
backwards_compat_TSFui("TriSurfField<unsigned_int>", "Field",
		       GenericField<TSMesh, FDuintBasis,
		       std::vector<unsigned int> >::maker,
		       GenericField<TSMesh, CFDuintBasis,
		       std::vector<unsigned int> >::maker);
PersistentTypeID
backwards_compat_TSFus("TriSurfField<unsigned_short>", "Field",
		       GenericField<TSMesh, FDushortBasis,
		       std::vector<unsigned short> >::maker,
		       GenericField<TSMesh, CFDushortBasis,
		       std::vector<unsigned short> >::maker);
PersistentTypeID
backwards_compat_TSFuc("TriSurfField<unsigned_char>", "Field",
		       GenericField<TSMesh, FDucharBasis,
		       std::vector<unsigned char> >::maker,
		       GenericField<TSMesh, CFDucharBasis,
		       std::vector<unsigned char> >::maker);
PersistentTypeID
backwards_compat_TSFul("TriSurfField<unsigned_long>", "Field",
		       GenericField<TSMesh, FDulongBasis,
		       std::vector<unsigned long> >::maker,
		       GenericField<TSMesh, CFDulongBasis,
		       std::vector<unsigned long> >::maker);

//Linear
typedef CrvLinearLgn<Tensor>                CrFDTensorBasis;
typedef CrvLinearLgn<Vector>                CrFDVectorBasis;
typedef CrvLinearLgn<double>                CrFDdoubleBasis;
typedef CrvLinearLgn<float>                 CrFDfloatBasis;
typedef CrvLinearLgn<int>                   CrFDintBasis;
typedef CrvLinearLgn<long long>             CrFDlonglongBasis;
typedef CrvLinearLgn<short>                 CrFDshortBasis;
typedef CrvLinearLgn<char>                  CrFDcharBasis;
typedef CrvLinearLgn<unsigned int>          CrFDuintBasis;
typedef CrvLinearLgn<unsigned short>        CrFDushortBasis;
typedef CrvLinearLgn<unsigned char>         CrFDucharBasis;
typedef CrvLinearLgn<unsigned long>         CrFDulongBasis;

typedef CurveMesh<CrvLinearLgn<Point> > CMesh;
PersistentTypeID backwards_compat_CM("CurveMesh", "Mesh",
				      CMesh::maker, CMesh::maker);

namespace SCIRun {

  template class CurveMesh<CrvLinearLgn<Point> >;

//NoData
template class GenericField<CMesh, NDBasis,  std::vector<double> >;

//Constant
template class GenericField<CMesh, CFDTensorBasis, std::vector<Tensor> >;
template class GenericField<CMesh, CFDVectorBasis, std::vector<Vector> >;
template class GenericField<CMesh, CFDdoubleBasis, std::vector<double> >;
template class GenericField<CMesh, CFDfloatBasis,  std::vector<float> >;
template class GenericField<CMesh, CFDintBasis,    std::vector<int> >;
template class GenericField<CMesh, CFDlonglongBasis,std::vector<long long> >;
template class GenericField<CMesh, CFDshortBasis,  std::vector<short> >;
template class GenericField<CMesh, CFDcharBasis,   std::vector<char> >;
template class GenericField<CMesh, CFDuintBasis,   std::vector<unsigned int> >;
template class GenericField<CMesh, CFDushortBasis, std::vector<unsigned short> >;
template class GenericField<CMesh, CFDucharBasis,  std::vector<unsigned char> >;
template class GenericField<CMesh, CFDulongBasis,  std::vector<unsigned long> >;

//Linear
template class GenericField<CMesh, CrFDTensorBasis, std::vector<Tensor> >;
template class GenericField<CMesh, CrFDVectorBasis, std::vector<Vector> >;
template class GenericField<CMesh, CrFDdoubleBasis, std::vector<double> >;
template class GenericField<CMesh, CrFDfloatBasis,  std::vector<float> >;
template class GenericField<CMesh, CrFDintBasis,    std::vector<int> >;
template class GenericField<CMesh, CrFDlonglongBasis,std::vector<long long> >;
template class GenericField<CMesh, CrFDshortBasis,  std::vector<short> >;
template class GenericField<CMesh, CrFDcharBasis,   std::vector<char> >;
template class GenericField<CMesh, CrFDuintBasis,   std::vector<unsigned int> >;
template class GenericField<CMesh, CrFDushortBasis, std::vector<unsigned short> >;
template class GenericField<CMesh, CrFDucharBasis,  std::vector<unsigned char> >;
template class GenericField<CMesh, CrFDulongBasis,  std::vector<unsigned long> >;
}

PersistentTypeID
backwards_compat_CFT("CurveField<Tensor>", "Field",
		     GenericField<CMesh, CrFDTensorBasis,
		     std::vector<Tensor> >::maker,
		     GenericField<CMesh, CFDTensorBasis,
		     std::vector<Tensor> >::maker);
PersistentTypeID
backwards_compat_CFV("CurveField<Vector>", "Field",
		     GenericField<CMesh, CrFDVectorBasis,
		     std::vector<Vector> >::maker,
		     GenericField<CMesh, CFDVectorBasis,
		     std::vector<Vector> >::maker);
PersistentTypeID
backwards_compat_CFd("CurveField<double>", "Field",
		     GenericField<CMesh, CrFDdoubleBasis,
		     std::vector<double> >::maker,
		     GenericField<CMesh, CFDdoubleBasis,
		     std::vector<double> >::maker,
		     GenericField<CMesh, NDBasis,
		     std::vector<double> >::maker);
PersistentTypeID
backwards_compat_CFf("CurveField<float>", "Field",
		     GenericField<CMesh, CrFDfloatBasis,
		     std::vector<float> >::maker,
		     GenericField<CMesh, CFDfloatBasis,
		     std::vector<float> >::maker);
PersistentTypeID
backwards_compat_CFi("CurveField<int>", "Field",
		     GenericField<CMesh, CrFDintBasis,
		     std::vector<int> >::maker,
		     GenericField<CMesh, CFDintBasis,
		     std::vector<int> >::maker);
PersistentTypeID
backwards_compat_CFs("CurveField<short>", "Field",
		     GenericField<CMesh, CrFDshortBasis,
		     std::vector<short> >::maker,
		     GenericField<CMesh, CFDshortBasis,
		     std::vector<short> >::maker);
PersistentTypeID
backwards_compat_CFc("CurveField<char>", "Field",
		     GenericField<CMesh, CrFDcharBasis,
		     std::vector<char> >::maker,
		     GenericField<CMesh, CFDcharBasis,
		     std::vector<char> >::maker);
PersistentTypeID
backwards_compat_CFui("CurveField<unsigned_int>", "Field",
		      GenericField<CMesh, CrFDuintBasis,
		      std::vector<unsigned int> >::maker,
		      GenericField<CMesh, CFDuintBasis,
		      std::vector<unsigned int> >::maker);
PersistentTypeID
backwards_compat_CFus("CurveField<unsigned_short>", "Field",
		      GenericField<CMesh, CrFDushortBasis,
		      std::vector<unsigned short> >::maker,
		      GenericField<CMesh, CFDushortBasis,
		      std::vector<unsigned short> >::maker);
PersistentTypeID
backwards_compat_CFuc("CurveField<unsigned_char>", "Field",
		      GenericField<CMesh, CrFDucharBasis,
		      std::vector<unsigned char> >::maker,
		      GenericField<CMesh, CFDucharBasis,
		      std::vector<unsigned char> >::maker);
PersistentTypeID
backwards_compat_CFul("CurveField<unsigned_long>", "Field",
		      GenericField<CMesh, CrFDulongBasis,
		      std::vector<unsigned long> >::maker,
		      GenericField<CMesh, CFDulongBasis,
		      std::vector<unsigned long> >::maker);
<|endoftext|>


<commit_before>#include "test.hpp"
#include "cppa/cppa.hpp"

using namespace cppa;
using namespace cppa::placeholders;

struct popular_actor : event_based_actor { // popular actors have a buddy
    actor_ptr m_buddy;
    popular_actor(const actor_ptr& buddy) : m_buddy(buddy) { }
    inline const actor_ptr& buddy() const { return m_buddy; }
    void report_failure() {
        send(buddy(), atom("failure"));
        self->quit();
    }
};

/******************************************************************************\
 *                                test case 1:                                *
 *                                                                            *
 *                  A                  B                  C                   *
 *                  |                  |                  |                   *
 *                  | --(sync_send)--> |                  |                   *
 *                  |                  | --(forward)----> |                   *
 *                  |                  X                  |---\               *
 *                  |                                     |   |               *
 *                  |                                     |<--/               *
 *                  | <-------------(reply)-------------- |                   *
 *                  X                                     X                   *
\******************************************************************************/

struct A : popular_actor {
    A(const actor_ptr& buddy) : popular_actor(buddy) { }
    void init() {
        become (
            on(atom("go"), arg_match) >> [=](const actor_ptr& next) {
                sync_send(next, atom("gogo")).then([=] {
                    send(buddy(), atom("success"));
                    quit();
                });
            },
            others() >> [=] { report_failure(); }
        );
    }
};

#ifdef __clang__
struct B : sb_actor<B,popular_actor> {
    B(const actor_ptr& buddy) : sb_actor<B,popular_actor>(buddy) { }
    behavior init_state = (
        others() >> [=] {
            forward_to(buddy());
            quit();
        }
    );
};
#else
struct B : popular_actor {
    B(const actor_ptr& buddy) : popular_actor(buddy) { }
    void init() {
        become (
            others() >> [=] {
                forward_to(buddy());
                quit();
            }
        );
    }
};
#endif

struct C : sb_actor<C> {
    behavior init_state = (
        on(atom("gogo")) >> [=] {
            reply(atom("gogogo"));
            self->quit();
        }
    );
};

/******************************************************************************\
 *                                test case 2:                                *
 *                                                                            *
 *                  A                  D                  C                   *
 *                  |                  |                  |                   *
 *                  | --(sync_send)--> |                  |                   *
 *                  |                  | --(sync_send)--> |                   *
 *                  |                  |                  |---\               *
 *                  |                  |                  |   |               *
 *                  |                  |                  |<--/               *
 *                  |                  | <---(reply)----- |                   *
 *                  | <---(reply)----- |                                      *
 *                  X                  X                                      *
\******************************************************************************/

struct D : popular_actor {
    response_handle m_handle;
    D(const actor_ptr& buddy) : popular_actor(buddy) { }
    void init() {
        become (
            others() >> [=] {
                m_handle = make_response_handle();
                sync_send_tuple(buddy(), last_dequeued()).then([=] {
                    m_handle.apply(last_dequeued());
                    quit();
                });
            }
        );
    }
};

int main() {
    CPPA_TEST(test__sync_send);
    auto await_success_message = [&] {
        receive (
            on(atom("success")) >> CPPA_CHECKPOINT_CB(),
            on(atom("failure")) >> CPPA_ERROR_CB("A didn't receive sync response"),
            on(atom("DOWN"), arg_match).when(_x2 != exit_reason::normal)
            >> [&](uint32_t err) {
                CPPA_ERROR("A exited for reason " << err);
            }
        );
    };
    send(spawn_monitor<A>(self), atom("go"), spawn<B>(spawn<C>()));
    await_success_message();
    await_all_others_done();
    send(spawn_monitor<A>(self), atom("go"), spawn<D>(spawn<C>()));
    await_success_message();
    await_all_others_done();
    timed_sync_send(self, std::chrono::milliseconds(50), atom("NoWay")).await(
        on(atom("TIMEOUT")) >> CPPA_CHECKPOINT_CB(),
        others() >> CPPA_UNEXPECTED_MSG_CB()
    );
    // we should have received two DOWN messages with normal exit reason
    int i = 0;
    receive_for(i, 2) (
        on(atom("DOWN"), exit_reason::normal) >> CPPA_CHECKPOINT_CB(),
        others() >> CPPA_UNEXPECTED_MSG_CB(),
        after(std::chrono::seconds(0)) >> CPPA_UNEXPECTED_TOUT_CB()
    );
    shutdown();
    return CPPA_TEST_RESULT;
}
<commit_msg>check whether mailbox is empty at end of unit test<commit_after>#include "test.hpp"
#include "cppa/cppa.hpp"

using namespace cppa;
using namespace cppa::placeholders;

struct popular_actor : event_based_actor { // popular actors have a buddy
    actor_ptr m_buddy;
    popular_actor(const actor_ptr& buddy) : m_buddy(buddy) { }
    inline const actor_ptr& buddy() const { return m_buddy; }
    void report_failure() {
        send(buddy(), atom("failure"));
        self->quit();
    }
};

/******************************************************************************\
 *                                test case 1:                                *
 *                                                                            *
 *                  A                  B                  C                   *
 *                  |                  |                  |                   *
 *                  | --(sync_send)--> |                  |                   *
 *                  |                  | --(forward)----> |                   *
 *                  |                  X                  |---\               *
 *                  |                                     |   |               *
 *                  |                                     |<--/               *
 *                  | <-------------(reply)-------------- |                   *
 *                  X                                     X                   *
\******************************************************************************/

struct A : popular_actor {
    A(const actor_ptr& buddy) : popular_actor(buddy) { }
    void init() {
        become (
            on(atom("go"), arg_match) >> [=](const actor_ptr& next) {
                sync_send(next, atom("gogo")).then([=] {
                    send(buddy(), atom("success"));
                    quit();
                });
            },
            others() >> [=] { report_failure(); }
        );
    }
};

#ifdef __clang__
struct B : sb_actor<B,popular_actor> {
    B(const actor_ptr& buddy) : sb_actor<B,popular_actor>(buddy) { }
    behavior init_state = (
        others() >> [=] {
            forward_to(buddy());
            quit();
        }
    );
};
#else
struct B : popular_actor {
    B(const actor_ptr& buddy) : popular_actor(buddy) { }
    void init() {
        become (
            others() >> [=] {
                forward_to(buddy());
                quit();
            }
        );
    }
};
#endif

struct C : sb_actor<C> {
    behavior init_state = (
        on(atom("gogo")) >> [=] {
            reply(atom("gogogo"));
            self->quit();
        }
    );
};

/******************************************************************************\
 *                                test case 2:                                *
 *                                                                            *
 *                  A                  D                  C                   *
 *                  |                  |                  |                   *
 *                  | --(sync_send)--> |                  |                   *
 *                  |                  | --(sync_send)--> |                   *
 *                  |                  |                  |---\               *
 *                  |                  |                  |   |               *
 *                  |                  |                  |<--/               *
 *                  |                  | <---(reply)----- |                   *
 *                  | <---(reply)----- |                                      *
 *                  X                  X                                      *
\******************************************************************************/

struct D : popular_actor {
    response_handle m_handle;
    D(const actor_ptr& buddy) : popular_actor(buddy) { }
    void init() {
        become (
            others() >> [=] {
                m_handle = make_response_handle();
                sync_send_tuple(buddy(), last_dequeued()).then([=] {
                    m_handle.apply(last_dequeued());
                    quit();
                });
            }
        );
    }
};

int main() {
    CPPA_TEST(test__sync_send);
    auto await_success_message = [&] {
        receive (
            on(atom("success")) >> CPPA_CHECKPOINT_CB(),
            on(atom("failure")) >> CPPA_ERROR_CB("A didn't receive sync response"),
            on(atom("DOWN"), arg_match).when(_x2 != exit_reason::normal)
            >> [&](uint32_t err) {
                CPPA_ERROR("A exited for reason " << err);
            }
        );
    };
    send(spawn_monitor<A>(self), atom("go"), spawn<B>(spawn<C>()));
    await_success_message();
    await_all_others_done();
    send(spawn_monitor<A>(self), atom("go"), spawn<D>(spawn<C>()));
    await_success_message();
    await_all_others_done();
    timed_sync_send(self, std::chrono::milliseconds(50), atom("NoWay")).await(
        on(atom("TIMEOUT")) >> CPPA_CHECKPOINT_CB(),
        others() >> CPPA_UNEXPECTED_MSG_CB()
    );
    // we should have received two DOWN messages with normal exit reason
    // plus 'NoWay'
    int i = 0;
    receive_for(i, 3) (
        on(atom("DOWN"), exit_reason::normal) >> CPPA_CHECKPOINT_CB(),
        on(atom("NoWay")) >> CPPA_CHECKPOINT_CB(),
        others() >> CPPA_UNEXPECTED_MSG_CB(),
        after(std::chrono::seconds(0)) >> CPPA_UNEXPECTED_TOUT_CB()
    );
    CPPA_CHECKPOINT();
    // mailbox should be empty now
    receive (
        others() >> CPPA_UNEXPECTED_MSG_CB(),
        after(std::chrono::seconds(0)) >> CPPA_CHECKPOINT_CB()
    );
    shutdown();
    return CPPA_TEST_RESULT;
}
<|endoftext|>


<commit_before>/*
 * ObjectControllerImplementation.cpp
 *
 *  Created on: 11/08/2009
 *      Author: victor
 */

#include "ObjectController.h"
#include "server/zone/ZoneServer.h"
#include "server/zone/managers/objectcontroller/command/CommandConfigManager.h"
#include "server/zone/managers/objectcontroller/command/CommandList.h"

#include "server/zone/objects/creature/LuaCreatureObject.h"
#include "server/zone/objects/player/PlayerCreature.h"
#include "server/zone/objects/player/PlayerObject.h"

#include "server/db/ServerDatabase.h"

void ObjectControllerImplementation::loadCommands() {
	configManager = new CommandConfigManager(server);
	queueCommands = new CommandList();

	info("loading queue commands...", true);
	configManager->loadSlashCommandsFile(queueCommands);
	configManager->registerSpecialCommands();

	StringBuffer infoMsg;
	infoMsg << "loaded " << queueCommands->size() << " commands";
	info(infoMsg.toString(), true);

	// LUA
	init();
	Luna<LuaCreatureObject>::Register(L);
}

void ObjectControllerImplementation::finalize() {
	info("deleting object controller", true);

	delete configManager;
	configManager = NULL;

	CommandConfigManager::slashCommands = NULL;

	delete queueCommands;
	queueCommands = NULL;
}

bool ObjectControllerImplementation::transferObject(SceneObject* objectToTransfer, SceneObject* destinationObject, int containmentType, bool notifyClient) {
	ManagedReference<SceneObject*> parent = objectToTransfer->getParent();

	if (parent == NULL) {
		error("objectToTransfer parent is NULL in ObjectManager::transferObject");
		return false;
	}

	if (destinationObject->getZone() != NULL && objectToTransfer->getZone() == NULL)
		destinationObject->broadcastObject(objectToTransfer, false);

	uint32 oldContainmentType = objectToTransfer->getContainmentType();

	//What about nested containers inside of the inventory...
	SceneObject* playerParent = objectToTransfer->getParentRecursively(SceneObject::PLAYERCREATURE);

	if (playerParent != NULL && destinationObject->isCellObject())
		objectToTransfer->sendDestroyTo(playerParent);

	if (parent->isCellObject()) {
		objectToTransfer->removeFromZone();
		parent->removeObject(objectToTransfer, false);
	} else {
		if (!parent->removeObject(objectToTransfer)) {
			error("could not remove objectToTransfer from parent in ObjectManager::transferObject");
			return false;
		}
	}

	if (parent->isCellObject()) {
		objectToTransfer->sendTo(destinationObject->getParent(), true);
	}

	if (!destinationObject->addObject(objectToTransfer, containmentType, notifyClient)) {
		error("could not add objectToTransfer to destinationObject in ObjectManager::transferObject");
		parent->addObject(objectToTransfer, oldContainmentType);

		if (parent->isCellObject()) {
			Zone* zne = destinationObject->getParent()->getZone();

			objectToTransfer->insertToZone(zne);
		}

		return false;
	}

	if (destinationObject->isCellObject()) {
		if (destinationObject->getParent() != NULL) {
			Zone* zne = destinationObject->getParent()->getZone();

			if (zne != NULL) {
				objectToTransfer->insertToZone(zne);
				//System::out << "Inserted to zone" << endl;
			}
		}
	}

	if (parent->isContainerObject() && parent->getGameObjectType() == SceneObject::STATICLOOTCONTAINER) {
		objectToTransfer->sendTo(destinationObject, true);
	}

	if (destinationObject->isPlayerCreature() && parent->isCellObject())
		objectToTransfer->sendTo(destinationObject, true);

	parent->updateToDatabase();
	//destinationObject->updateToDatabaseAllObjects(false);

	return true;
}

float ObjectControllerImplementation::activateCommand(CreatureObject* object, unsigned int actionCRC, unsigned int actionCount, uint64 targetID, const UnicodeString& arguments) {
	// Pre: object is wlocked
	// Post: object is wlocked

	QueueCommand* queueCommand = getQueueCommand(actionCRC);

	float durationTime = 0.f;

	if (queueCommand == NULL) {
		StringBuffer msg;
		msg << "unregistered queue command 0x" << hex << actionCRC << " arguments: " << arguments.toString();
		object->error(msg.toString());

		return 0.f;
	}

	/*StringBuffer infoMsg;
	infoMsg << "activating queue command 0x" << hex << actionCRC << " " << queueCommand->getQueueCommandName() << " arguments='" << arguments.toString() << "'";
	object->info(infoMsg.toString(), true);*/

	String characterAbility = queueCommand->getCharacterAbility();

	if (characterAbility.length() > 1) {
		object->info("activating characterAbility " + characterAbility);

		if (object->isPlayerCreature()) {
			PlayerObject* playerObject = (PlayerObject*) object->getSlottedObject("ghost");

			if (!playerObject->hasSkill(characterAbility)) {
				object->clearQueueAction(actionCount, 0, 2);

				return 0.f;
			}
		}
	}

	int errorNumber = queueCommand->doQueueCommand(object, targetID, arguments);

	//onFail onComplete must clear the action from client queue
	if (errorNumber != QueueCommand::SUCCESS)
		queueCommand->onFail(actionCount, object, errorNumber);
	else {
		if (queueCommand->getDefaultPriority() != QueueCommand::IMMEDIATE)
			durationTime = queueCommand->getCommandDuration(object);

		queueCommand->onComplete(actionCount, object, durationTime);
	}

	return durationTime;
}

void ObjectControllerImplementation::addQueueCommand(QueueCommand* command) {
	queueCommands->put(command);
}

QueueCommand* ObjectControllerImplementation::getQueueCommand(const String& name) {
	return queueCommands->getSlashCommand(name);
}

QueueCommand* ObjectControllerImplementation::getQueueCommand(uint32 crc) {
	return queueCommands->getSlashCommand(crc);
}
<commit_msg>[fixed] ObjectController<commit_after>/*
 * ObjectControllerImplementation.cpp
 *
 *  Created on: 11/08/2009
 *      Author: victor
 */

#include "ObjectController.h"
#include "server/zone/ZoneServer.h"
#include "server/zone/managers/objectcontroller/command/CommandConfigManager.h"
#include "server/zone/managers/objectcontroller/command/CommandList.h"

#include "server/zone/objects/creature/LuaCreatureObject.h"
#include "server/zone/objects/player/PlayerCreature.h"
#include "server/zone/objects/player/PlayerObject.h"

#include "server/db/ServerDatabase.h"

void ObjectControllerImplementation::loadCommands() {
	configManager = new CommandConfigManager(server);
	queueCommands = new CommandList();

	info("loading queue commands...", true);
	configManager->loadSlashCommandsFile(queueCommands);
	configManager->registerSpecialCommands();

	StringBuffer infoMsg;
	infoMsg << "loaded " << queueCommands->size() << " commands";
	info(infoMsg.toString(), true);

	// LUA
	init();
	Luna<LuaCreatureObject>::Register(L);
}

void ObjectControllerImplementation::finalize() {
	info("deleting object controller", true);

	delete configManager;
	configManager = NULL;

	CommandConfigManager::slashCommands = NULL;

	delete queueCommands;
	queueCommands = NULL;
}

bool ObjectControllerImplementation::transferObject(SceneObject* objectToTransfer, SceneObject* destinationObject, int containmentType, bool notifyClient) {
	ManagedReference<SceneObject*> parent = objectToTransfer->getParent();

	if (parent == NULL) {
		error("objectToTransfer parent is NULL in ObjectManager::transferObject");
		return false;
	}

	if (destinationObject->getZone() != NULL && objectToTransfer->getZone() == NULL)
		destinationObject->broadcastObject(objectToTransfer, false);

	uint32 oldContainmentType = objectToTransfer->getContainmentType();

	//What about nested containers inside of the inventory...
	SceneObject* playerParent = objectToTransfer->getParentRecursively(SceneObject::PLAYERCREATURE);

	if (playerParent != NULL && destinationObject->isCellObject())
		objectToTransfer->sendDestroyTo(playerParent);

	if (parent->isCellObject()) {
		objectToTransfer->removeFromZone();
		parent->removeObject(objectToTransfer, false);
	} else {
		if (!parent->removeObject(objectToTransfer)) {
			error("could not remove objectToTransfer from parent in ObjectManager::transferObject");
			return false;
		}
	}

	if (parent->isCellObject()) {
		objectToTransfer->sendTo(destinationObject->getParent(), true);
	}

	if (!destinationObject->addObject(objectToTransfer, containmentType, notifyClient)) {
		error("could not add objectToTransfer to destinationObject in ObjectManager::transferObject");
		parent->addObject(objectToTransfer, oldContainmentType);

		if (parent->isCellObject()) {
			Zone* zne = destinationObject->getParent()->getZone();

			objectToTransfer->insertToZone(zne);
		}

		return false;
	}

	if (destinationObject->isCellObject()) {
		if (destinationObject->getParent() != NULL) {
			Zone* zne = destinationObject->getParent()->getZone();

			if (zne != NULL) {
				objectToTransfer->insertToZone(zne);
				//System::out << "Inserted to zone" << endl;
			}
		}
	}

	if (parent->isContainerObject() && parent->getGameObjectType() == SceneObject::STATICLOOTCONTAINER) {
		objectToTransfer->sendTo(destinationObject, true);
	}

	if (objectToTransfer->isContainerObject()) {
		objectToTransfer->sendTo(destinationObject, true);
	}

	if (destinationObject->isPlayerCreature() && parent->isCellObject())
		objectToTransfer->sendTo(destinationObject, true);

	parent->updateToDatabase();
	//destinationObject->updateToDatabaseAllObjects(false);

	return true;
}

float ObjectControllerImplementation::activateCommand(CreatureObject* object, unsigned int actionCRC, unsigned int actionCount, uint64 targetID, const UnicodeString& arguments) {
	// Pre: object is wlocked
	// Post: object is wlocked

	QueueCommand* queueCommand = getQueueCommand(actionCRC);

	float durationTime = 0.f;

	if (queueCommand == NULL) {
		StringBuffer msg;
		msg << "unregistered queue command 0x" << hex << actionCRC << " arguments: " << arguments.toString();
		object->error(msg.toString());

		return 0.f;
	}

	/*StringBuffer infoMsg;
	infoMsg << "activating queue command 0x" << hex << actionCRC << " " << queueCommand->getQueueCommandName() << " arguments='" << arguments.toString() << "'";
	object->info(infoMsg.toString(), true);*/

	String characterAbility = queueCommand->getCharacterAbility();

	if (characterAbility.length() > 1) {
		object->info("activating characterAbility " + characterAbility);

		if (object->isPlayerCreature()) {
			PlayerObject* playerObject = (PlayerObject*) object->getSlottedObject("ghost");

			if (!playerObject->hasSkill(characterAbility)) {
				object->clearQueueAction(actionCount, 0, 2);

				return 0.f;
			}
		}
	}

	int errorNumber = queueCommand->doQueueCommand(object, targetID, arguments);

	//onFail onComplete must clear the action from client queue
	if (errorNumber != QueueCommand::SUCCESS)
		queueCommand->onFail(actionCount, object, errorNumber);
	else {
		if (queueCommand->getDefaultPriority() != QueueCommand::IMMEDIATE)
			durationTime = queueCommand->getCommandDuration(object);

		queueCommand->onComplete(actionCount, object, durationTime);
	}

	return durationTime;
}

void ObjectControllerImplementation::addQueueCommand(QueueCommand* command) {
	queueCommands->put(command);
}

QueueCommand* ObjectControllerImplementation::getQueueCommand(const String& name) {
	return queueCommands->getSlashCommand(name);
}

QueueCommand* ObjectControllerImplementation::getQueueCommand(uint32 crc) {
	return queueCommands->getSlashCommand(crc);
}
<|endoftext|>