<commit_before>/******************************************************************************
 *                       ____    _    _____                                   *
 *                      / ___|  / \  |  ___|    C++                           *
 *                     | |     / _ \ | |_       Actor                         *
 *                     | |___ / ___ \|  _|      Framework                     *
 *                      \____/_/   \_|_|                                      *
 *                                                                            *
 * Copyright (C) 2011 - 2017                                                  *
 * Dominik Charousset <dominik.charousset (at) haw-hamburg.de>                *
 *                                                                            *
 * Distributed under the terms and conditions of the BSD 3-Clause License or  *
 * (at your option) under the terms and conditions of the Boost Software      *
 * License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE.       *
 *                                                                            *
 * If you did not receive a copy of the license files, see                    *
 * http://opensource.org/licenses/BSD-3-Clause and                            *
 * http://www.boost.org/LICENSE_1_0.txt.                                      *
 ******************************************************************************/

#ifndef CAF_TYPED_ACTOR_HPP
#define CAF_TYPED_ACTOR_HPP

#include <cstddef>

#include "caf/actor.hpp"
#include "caf/make_actor.hpp"
#include "caf/actor_cast.hpp"
#include "caf/replies_to.hpp"
#include "caf/actor_system.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/composed_type.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/typed_behavior.hpp"
#include "caf/typed_response_promise.hpp"
#include "caf/unsafe_actor_handle_init.hpp"

#include "caf/detail/mpi_splice.hpp"
#include "caf/decorator/splitter.hpp"
#include "caf/decorator/sequencer.hpp"

namespace caf {

template <class... Sigs>
class typed_event_based_actor;

namespace io {

template <class... Sigs>
class typed_broker;

} // namespace io

/// Identifies a statically typed actor.
/// @tparam Sigs Signature of this actor as `replies_to<...>::with<...>`
///              parameter pack.
template <class... Sigs>
class typed_actor : detail::comparable<typed_actor<Sigs...>>,
                    detail::comparable<typed_actor<Sigs...>, actor>,
                    detail::comparable<typed_actor<Sigs...>, actor_addr>,
                    detail::comparable<typed_actor<Sigs...>, strong_actor_ptr> {
 public:
  static_assert(sizeof...(Sigs) > 0, "Empty typed actor handle");

  // -- friend types that need access to private ctors
  friend class local_actor;

  template <class>
  friend class data_processor;

  template <class>
  friend class detail::type_erased_value_impl;

  template <class...>
  friend class typed_actor;

  // allow conversion via actor_cast
  template <class, class, int>
  friend class actor_cast_access;

  // tell actor_cast which semantic this type uses
  static constexpr bool has_weak_ptr_semantics = false;

  /// Creates a new `typed_actor` type by extending this one with `Es...`.
  template <class... Es>
  using extend = typed_actor<Sigs..., Es...>;

  /// Creates a new `typed_actor` type by extending this one with another
  /// `typed_actor`.
  template <class... Ts>
  using extend_with =
    typename detail::extend_with_helper<typed_actor, Ts...>::type;

  /// Identifies the behavior type actors of this kind use
  /// for their behavior stack.
  using behavior_type = typed_behavior<Sigs...>;

  /// Identifies pointers to instances of this kind of actor.
  using pointer = typed_event_based_actor<Sigs...>*;

  /// Identifies the base class for this kind of actor.
  using base = typed_event_based_actor<Sigs...>;

  /// Identifies pointers to brokers implementing this interface.
  using broker_pointer = io::typed_broker<Sigs...>*;

  /// Identifies the base class of brokers implementing this interface.
  using broker_base = io::typed_broker<Sigs...>;

  /// Stores the template parameter pack.
  using signatures = detail::type_list<Sigs...>;

  /// Identifies the base class for this kind of actor with actor.
  template <class State>
  using stateful_base = stateful_actor<State, base>;

  /// Identifies the base class for this kind of actor with actor.
  template <class State>
  using stateful_pointer = stateful_actor<State, base>*;

  /// Identifies the broker_base class for this kind of actor with actor.
  template <class State>
  using stateful_broker_base =
    stateful_actor<State, broker_base>;

  /// Identifies the broker_base class for this kind of actor with actor.
  template <class State>
  using stateful_broker_pointer =
    stateful_actor<State, broker_base>*;

  typed_actor() = default;
  typed_actor(typed_actor&&) = default;
  typed_actor(const typed_actor&) = default;
  typed_actor& operator=(typed_actor&&) = default;
  typed_actor& operator=(const typed_actor&) = default;

  template <class... Ts>
  typed_actor(const typed_actor<Ts...>& other) : ptr_(other.ptr_) {
    static_assert(detail::tl_subset_of<
                    signatures,
                    detail::type_list<Ts...>
                  >::value,
                  "Cannot assign incompatible handle");
  }

  // allow `handle_type{this}` for typed actors
  template <class T>
  typed_actor(T* ptr,
              typename std::enable_if<
                std::is_base_of<statically_typed_actor_base, T>::value
              >::type* = 0)
      : ptr_(ptr->ctrl()) {
    static_assert(detail::tl_subset_of<
                    signatures,
                    typename T::signatures
                  >::value,
                  "Cannot assign T* to incompatible handle type");
    CAF_ASSERT(ptr != nullptr);
  }

  template <class... Ts>
  typed_actor& operator=(const typed_actor<Ts...>& other) {
    static_assert(detail::tl_subset_of<
                    signatures,
                    detail::type_list<Ts...>
                  >::value,
                  "Cannot assign incompatible handle");
    ptr_ = other.ptr_;
    return *this;
  }

  inline typed_actor& operator=(std::nullptr_t) {
    ptr_.reset();
    return *this;
  }

  explicit typed_actor(const unsafe_actor_handle_init_t&) CAF_DEPRECATED {
    // nop
  }

  /// Queries whether this actor handle is valid.
  inline explicit operator bool() const {
    return static_cast<bool>(ptr_);
  }

  /// Queries whether this actor handle is invalid.
  inline bool operator!() const {
    return !ptr_;
  }

  /// Queries the address of the stored actor.
  actor_addr address() const noexcept {
    return {ptr_.get(), true};
  }

  /// Returns the ID of this actor.
  actor_id id() const noexcept {
    return ptr_->id();
  }

  /// Returns the origin node of this actor.
  node_id node() const noexcept {
    return ptr_->node();
  }

  /// Returns the hosting actor system.
  inline actor_system& home_system() const noexcept {
    return *ptr_->home_system;
  }

  /// Exchange content of `*this` and `other`.
  void swap(typed_actor& other) noexcept {
    ptr_.swap(other.ptr_);
  }

  /// Queries whether this object was constructed using
  /// `unsafe_actor_handle_init` or is in moved-from state.
  bool unsafe() const CAF_DEPRECATED {
    return !ptr_;
  }

  /// @cond PRIVATE

  abstract_actor* operator->() const noexcept {
    return ptr_->get();
  }

  abstract_actor& operator*() const noexcept {
    return *ptr_->get();
  }

  intptr_t compare(const typed_actor& x) const noexcept {
    return actor_addr::compare(get(), x.get());
  }

  intptr_t compare(const actor& x) const noexcept {
    return actor_addr::compare(get(), actor_cast<actor_control_block*>(x));
  }

  intptr_t compare(const actor_addr& x) const noexcept {
    return actor_addr::compare(get(), actor_cast<actor_control_block*>(x));
  }

  intptr_t compare(const strong_actor_ptr& x) const noexcept {
    return actor_addr::compare(get(), actor_cast<actor_control_block*>(x));
  }

  typed_actor(actor_control_block* ptr, bool add_ref) : ptr_(ptr, add_ref) {
    // nop
  }

  friend inline std::string to_string(const typed_actor& x) {
    return to_string(x.ptr_);
  }

  friend inline void append_to_string(std::string& x, const typed_actor& y) {
    return append_to_string(x, y.ptr_);
  }

  template <class Inspector>
  friend typename Inspector::result_type inspect(Inspector& f, typed_actor& x) {
    return f(x.ptr_);
  }

  /// Releases the reference held by handle `x`. Using the
  /// handle after invalidating it is undefined behavior.
  friend void destroy(typed_actor& x) {
    x.ptr_.reset();
  }

  /// @endcond

private:
  actor_control_block* get() const noexcept {
    return ptr_.get();
  }

  actor_control_block* release() noexcept {
    return ptr_.release();
  }

  typed_actor(actor_control_block* ptr) : ptr_(ptr) {
    // nop
  }

  strong_actor_ptr ptr_;
};

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator==(const typed_actor<Xs...>& x,
                const typed_actor<Ys...>& y) noexcept {
  return actor_addr::compare(actor_cast<actor_control_block*>(x),
                             actor_cast<actor_control_block*>(y)) == 0;
}

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator!=(const typed_actor<Xs...>& x,
                const typed_actor<Ys...>& y) noexcept {
  return !(x == y);
}

/// Returns a new actor that implements the composition `f.g(x) = f(g(x))`.
/// @relates typed_actor
template <class... Xs, class... Ys>
composed_type_t<detail::type_list<Xs...>, detail::type_list<Ys...>>
operator*(typed_actor<Xs...> f, typed_actor<Ys...> g) {
  using result = composed_type_t<detail::type_list<Xs...>,
                                 detail::type_list<Ys...>>;
  auto& sys = g->home_system();
  auto mts = sys.message_types(detail::type_list<result>{});
  return make_actor<decorator::sequencer, result>(
    sys.next_actor_id(), sys.node(), &sys,
    actor_cast<strong_actor_ptr>(std::move(f)),
    actor_cast<strong_actor_ptr>(std::move(g)), std::move(mts));
}

template <class... Xs, class... Ts>
typename detail::mpi_splice<
  typed_actor,
  detail::type_list<Xs...>,
  typename Ts::signatures...
>::type
splice(const typed_actor<Xs...>& x, const Ts&... xs) {
  using result =
    typename detail::mpi_splice<
      typed_actor,
      detail::type_list<Xs...>,
      typename Ts::signatures...
    >::type;
  std::vector<strong_actor_ptr> tmp{actor_cast<strong_actor_ptr>(x),
                                    actor_cast<strong_actor_ptr>(xs)...};
  auto& sys = x->home_system();
  auto mts = sys.message_types(detail::type_list<result>{});
  return make_actor<decorator::splitter, result>(sys.next_actor_id(),
                                                 sys.node(), &sys,
                                                 std::move(tmp),
                                                 std::move(mts));
}

} // namespace caf

// allow typed_actor to be used in hash maps
namespace std {
template <class... Sigs>
struct hash<caf::typed_actor<Sigs...>> {
  size_t operator()(const caf::typed_actor<Sigs...>& ref) const {
    return ref ? static_cast<size_t>(ref->id()) : 0;
  }
};
} // namespace std

#endif // CAF_TYPED_ACTOR_HPP
<commit_msg>Make typed actor comparable to nullptr_t<commit_after>/******************************************************************************
 *                       ____    _    _____                                   *
 *                      / ___|  / \  |  ___|    C++                           *
 *                     | |     / _ \ | |_       Actor                         *
 *                     | |___ / ___ \|  _|      Framework                     *
 *                      \____/_/   \_|_|                                      *
 *                                                                            *
 * Copyright (C) 2011 - 2017                                                  *
 * Dominik Charousset <dominik.charousset (at) haw-hamburg.de>                *
 *                                                                            *
 * Distributed under the terms and conditions of the BSD 3-Clause License or  *
 * (at your option) under the terms and conditions of the Boost Software      *
 * License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE.       *
 *                                                                            *
 * If you did not receive a copy of the license files, see                    *
 * http://opensource.org/licenses/BSD-3-Clause and                            *
 * http://www.boost.org/LICENSE_1_0.txt.                                      *
 ******************************************************************************/

#ifndef CAF_TYPED_ACTOR_HPP
#define CAF_TYPED_ACTOR_HPP

#include <cstddef>

#include "caf/actor.hpp"
#include "caf/make_actor.hpp"
#include "caf/actor_cast.hpp"
#include "caf/replies_to.hpp"
#include "caf/actor_system.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/composed_type.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/typed_behavior.hpp"
#include "caf/typed_response_promise.hpp"
#include "caf/unsafe_actor_handle_init.hpp"

#include "caf/detail/mpi_splice.hpp"
#include "caf/decorator/splitter.hpp"
#include "caf/decorator/sequencer.hpp"

namespace caf {

template <class... Sigs>
class typed_event_based_actor;

namespace io {

template <class... Sigs>
class typed_broker;

} // namespace io

/// Identifies a statically typed actor.
/// @tparam Sigs Signature of this actor as `replies_to<...>::with<...>`
///              parameter pack.
template <class... Sigs>
class typed_actor : detail::comparable<typed_actor<Sigs...>>,
                    detail::comparable<typed_actor<Sigs...>, actor>,
                    detail::comparable<typed_actor<Sigs...>, actor_addr>,
                    detail::comparable<typed_actor<Sigs...>, strong_actor_ptr> {
 public:
  static_assert(sizeof...(Sigs) > 0, "Empty typed actor handle");

  // -- friend types that need access to private ctors
  friend class local_actor;

  template <class>
  friend class data_processor;

  template <class>
  friend class detail::type_erased_value_impl;

  template <class...>
  friend class typed_actor;

  // allow conversion via actor_cast
  template <class, class, int>
  friend class actor_cast_access;

  // tell actor_cast which semantic this type uses
  static constexpr bool has_weak_ptr_semantics = false;

  /// Creates a new `typed_actor` type by extending this one with `Es...`.
  template <class... Es>
  using extend = typed_actor<Sigs..., Es...>;

  /// Creates a new `typed_actor` type by extending this one with another
  /// `typed_actor`.
  template <class... Ts>
  using extend_with =
    typename detail::extend_with_helper<typed_actor, Ts...>::type;

  /// Identifies the behavior type actors of this kind use
  /// for their behavior stack.
  using behavior_type = typed_behavior<Sigs...>;

  /// Identifies pointers to instances of this kind of actor.
  using pointer = typed_event_based_actor<Sigs...>*;

  /// Identifies the base class for this kind of actor.
  using base = typed_event_based_actor<Sigs...>;

  /// Identifies pointers to brokers implementing this interface.
  using broker_pointer = io::typed_broker<Sigs...>*;

  /// Identifies the base class of brokers implementing this interface.
  using broker_base = io::typed_broker<Sigs...>;

  /// Stores the template parameter pack.
  using signatures = detail::type_list<Sigs...>;

  /// Identifies the base class for this kind of actor with actor.
  template <class State>
  using stateful_base = stateful_actor<State, base>;

  /// Identifies the base class for this kind of actor with actor.
  template <class State>
  using stateful_pointer = stateful_actor<State, base>*;

  /// Identifies the broker_base class for this kind of actor with actor.
  template <class State>
  using stateful_broker_base =
    stateful_actor<State, broker_base>;

  /// Identifies the broker_base class for this kind of actor with actor.
  template <class State>
  using stateful_broker_pointer =
    stateful_actor<State, broker_base>*;

  typed_actor() = default;
  typed_actor(typed_actor&&) = default;
  typed_actor(const typed_actor&) = default;
  typed_actor& operator=(typed_actor&&) = default;
  typed_actor& operator=(const typed_actor&) = default;

  template <class... Ts>
  typed_actor(const typed_actor<Ts...>& other) : ptr_(other.ptr_) {
    static_assert(detail::tl_subset_of<
                    signatures,
                    detail::type_list<Ts...>
                  >::value,
                  "Cannot assign incompatible handle");
  }

  // allow `handle_type{this}` for typed actors
  template <class T>
  typed_actor(T* ptr,
              typename std::enable_if<
                std::is_base_of<statically_typed_actor_base, T>::value
              >::type* = 0)
      : ptr_(ptr->ctrl()) {
    static_assert(detail::tl_subset_of<
                    signatures,
                    typename T::signatures
                  >::value,
                  "Cannot assign T* to incompatible handle type");
    CAF_ASSERT(ptr != nullptr);
  }

  template <class... Ts>
  typed_actor& operator=(const typed_actor<Ts...>& other) {
    static_assert(detail::tl_subset_of<
                    signatures,
                    detail::type_list<Ts...>
                  >::value,
                  "Cannot assign incompatible handle");
    ptr_ = other.ptr_;
    return *this;
  }

  inline typed_actor& operator=(std::nullptr_t) {
    ptr_.reset();
    return *this;
  }

  explicit typed_actor(const unsafe_actor_handle_init_t&) CAF_DEPRECATED {
    // nop
  }

  /// Queries whether this actor handle is valid.
  inline explicit operator bool() const {
    return static_cast<bool>(ptr_);
  }

  /// Queries whether this actor handle is invalid.
  inline bool operator!() const {
    return !ptr_;
  }

  /// Queries the address of the stored actor.
  actor_addr address() const noexcept {
    return {ptr_.get(), true};
  }

  /// Returns the ID of this actor.
  actor_id id() const noexcept {
    return ptr_->id();
  }

  /// Returns the origin node of this actor.
  node_id node() const noexcept {
    return ptr_->node();
  }

  /// Returns the hosting actor system.
  inline actor_system& home_system() const noexcept {
    return *ptr_->home_system;
  }

  /// Exchange content of `*this` and `other`.
  void swap(typed_actor& other) noexcept {
    ptr_.swap(other.ptr_);
  }

  /// Queries whether this object was constructed using
  /// `unsafe_actor_handle_init` or is in moved-from state.
  bool unsafe() const CAF_DEPRECATED {
    return !ptr_;
  }

  /// @cond PRIVATE

  abstract_actor* operator->() const noexcept {
    return ptr_->get();
  }

  abstract_actor& operator*() const noexcept {
    return *ptr_->get();
  }

  intptr_t compare(const typed_actor& x) const noexcept {
    return actor_addr::compare(get(), x.get());
  }

  intptr_t compare(const actor& x) const noexcept {
    return actor_addr::compare(get(), actor_cast<actor_control_block*>(x));
  }

  intptr_t compare(const actor_addr& x) const noexcept {
    return actor_addr::compare(get(), actor_cast<actor_control_block*>(x));
  }

  intptr_t compare(const strong_actor_ptr& x) const noexcept {
    return actor_addr::compare(get(), actor_cast<actor_control_block*>(x));
  }

  typed_actor(actor_control_block* ptr, bool add_ref) : ptr_(ptr, add_ref) {
    // nop
  }

  friend inline std::string to_string(const typed_actor& x) {
    return to_string(x.ptr_);
  }

  friend inline void append_to_string(std::string& x, const typed_actor& y) {
    return append_to_string(x, y.ptr_);
  }

  template <class Inspector>
  friend typename Inspector::result_type inspect(Inspector& f, typed_actor& x) {
    return f(x.ptr_);
  }

  /// Releases the reference held by handle `x`. Using the
  /// handle after invalidating it is undefined behavior.
  friend void destroy(typed_actor& x) {
    x.ptr_.reset();
  }

  /// @endcond

private:
  actor_control_block* get() const noexcept {
    return ptr_.get();
  }

  actor_control_block* release() noexcept {
    return ptr_.release();
  }

  typed_actor(actor_control_block* ptr) : ptr_(ptr) {
    // nop
  }

  strong_actor_ptr ptr_;
};

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator==(const typed_actor<Xs...>& x,
                const typed_actor<Ys...>& y) noexcept {
  return actor_addr::compare(actor_cast<actor_control_block*>(x),
                             actor_cast<actor_control_block*>(y)) == 0;
}

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator!=(const typed_actor<Xs...>& x,
                const typed_actor<Ys...>& y) noexcept {
  return !(x == y);
}

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator==(const typed_actor<Xs...>& x, std::nullptr_t) noexcept {
  return actor_addr::compare(actor_cast<actor_control_block*>(x), nullptr) == 0;
}

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator==(std::nullptr_t, const typed_actor<Xs...>& x) noexcept {
  return actor_addr::compare(actor_cast<actor_control_block*>(x), nullptr) == 0;
}

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator!=(const typed_actor<Xs...>& x, std::nullptr_t) noexcept {
  return !(x == nullptr);
}

/// @relates typed_actor
template <class... Xs, class... Ys>
bool operator!=(std::nullptr_t, const typed_actor<Xs...>& x) noexcept {
  return !(x == nullptr);
}

/// Returns a new actor that implements the composition `f.g(x) = f(g(x))`.
/// @relates typed_actor
template <class... Xs, class... Ys>
composed_type_t<detail::type_list<Xs...>, detail::type_list<Ys...>>
operator*(typed_actor<Xs...> f, typed_actor<Ys...> g) {
  using result = composed_type_t<detail::type_list<Xs...>,
                                 detail::type_list<Ys...>>;
  auto& sys = g->home_system();
  auto mts = sys.message_types(detail::type_list<result>{});
  return make_actor<decorator::sequencer, result>(
    sys.next_actor_id(), sys.node(), &sys,
    actor_cast<strong_actor_ptr>(std::move(f)),
    actor_cast<strong_actor_ptr>(std::move(g)), std::move(mts));
}

template <class... Xs, class... Ts>
typename detail::mpi_splice<
  typed_actor,
  detail::type_list<Xs...>,
  typename Ts::signatures...
>::type
splice(const typed_actor<Xs...>& x, const Ts&... xs) {
  using result =
    typename detail::mpi_splice<
      typed_actor,
      detail::type_list<Xs...>,
      typename Ts::signatures...
    >::type;
  std::vector<strong_actor_ptr> tmp{actor_cast<strong_actor_ptr>(x),
                                    actor_cast<strong_actor_ptr>(xs)...};
  auto& sys = x->home_system();
  auto mts = sys.message_types(detail::type_list<result>{});
  return make_actor<decorator::splitter, result>(sys.next_actor_id(),
                                                 sys.node(), &sys,
                                                 std::move(tmp),
                                                 std::move(mts));
}

} // namespace caf

// allow typed_actor to be used in hash maps
namespace std {
template <class... Sigs>
struct hash<caf::typed_actor<Sigs...>> {
  size_t operator()(const caf::typed_actor<Sigs...>& ref) const {
    return ref ? static_cast<size_t>(ref->id()) : 0;
  }
};
} // namespace std

#endif // CAF_TYPED_ACTOR_HPP
<|endoftext|>


<commit_before>#include <iostream>

#include "SDL/SDL.h"
#include "SDL_image.h"
#include "SDL_gfxPrimitives.h"
#include "point.h"
#include "map.h"
#include "game.h"
#include "surface.h"
#include "eventfactory.h"

using namespace std;

Game::Game() {
  playing=true;
  screen=NULL;
  terrain=NULL;
  map_camera=NULL;
}

int Game::execute() {
  if (!init()) {
    cerr << "Errors occured when starting the game. Stopping." << endl;
    return 1;
  }

  SDL_Event event;

  while(playing) {
    SDL_PumpEvents();
    while(SDL_PollEvent(&event)) {
      onEvent(&event);
    }

    updateState();
    render();
    // SDL rest?
  }

  return cleanup();
}

int Game::init() {
  if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
    return false;
  }

  screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
  if(screen == NULL) {
     return false;
  }

  int flags = IMG_INIT_JPG | IMG_INIT_PNG;
  int initted=IMG_Init(flags);
  if( initted & flags != flags) {
    cout << "could not init SDL_Image" << endl;
    cout << "Reason: " << IMG_GetError() << endl;
    return false;
  }

  terrain = Surface::load("graphics/terrain.png");

  if (terrain == NULL) {
    cout << "Failed to read graphics/terrain.png data" << endl;
    return false;
  }

  shroud_edges = Surface::load("graphics/shroud_edges.bmp");

  if (shroud_edges == NULL) {
    cout << "Failed to read graphics/shroud_edges.bmp data" << endl;
    return false;
  }

  shroud_edges_shadow = Surface::load("graphics/shroud_edges_shadow.bmp");

  if (shroud_edges_shadow == NULL) {
    cout << "Failed to read graphics/shroud_edges_shadow.bmp data" << endl;
    return false;
  }

  SDL_ShowCursor(0);
  mouse.init(screen);

  map_camera = new MapCamera(0, 0, screen, &map);
  map.load("maps/4PL_Mountains.ini");
  unitRepository = new UnitRepository(&map);

  Unit* frigate = unitRepository->create(UNIT_FRIGATE, HOUSE_SARDAUKAR, 64, 64, 10);
  units.push_back(frigate);

  Unit* trike1 = unitRepository->create(UNIT_TRIKE, HOUSE_ATREIDES, 256, 256, 3);
  units.push_back(trike1);

  Unit* trike2 = unitRepository->create(UNIT_TRIKE, HOUSE_ATREIDES, 448, 448, 3);
  units.push_back(trike2);

  return true;
}

void Game::onEvent(SDL_Event* event) {
  if(event->type == SDL_QUIT) {
    playing = false;
  }

  mouse.onEvent(event);
  keyboard.onEvent(event);

  map_camera->onEvent(event);

  if (event->type == SDL_USEREVENT) {
    if (event->user.code == D2TM_SELECT) {
      D2TMSelectStruct *s = static_cast<D2TMSelectStruct*>(event->user.data1);

      Point p = map_camera->toWorldCoordinates(s->screen_position);

      if (mouse.is_pointing()) {
        Unit* selected_unit = NULL;
        for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
          if ((*it)->is_point_within(p)) {
            selected_unit = *it;
            break;
          }
        }

        if (selected_unit != NULL) {
          deselectAllUnits();
          selected_unit->select();
          mouse.state_order_move();
        }
      }

      delete s;
    } else if (event->user.code == D2TM_DESELECT) {
      mouse.state_pointing();
      deselectAllUnits();
    } else if (event->user.code == D2TM_BOX_SELECT) {
      D2TMBoxSelectStruct *s = static_cast<D2TMBoxSelectStruct*>(event->user.data1);

      Rectangle rectangle = map_camera->toWorldCoordinates(s->rectangle);

      if (mouse.is_pointing()) {
        mouse.state_pointing();

        deselectAllUnits();
        for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
          if ((*it)->is_within(rectangle)) {
            (*it)->select();
            mouse.state_order_move();
          }
        }
      }

      delete s;
    } else if (event->user.code == D2TM_MOVE_UNIT) {
      D2TMMoveUnitStruct *s = static_cast<D2TMMoveUnitStruct*>(event->user.data1);
      Point p = map_camera->toWorldCoordinates(s->screen_position);

      for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
        if ((*it)->is_selected()) {
          (*it)->order_move(p);
        }
      }

      delete s;
    }

  }

}

void Game::render() {
  SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));

  map_camera->draw(&map, terrain, screen);

  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    if ((*it)->is_on_air_layer()) map_camera->draw(*it, screen);
  }

  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    if ((*it)->is_on_ground_layer()) map_camera->draw(*it, screen);
  }

  map_camera->drawShroud(&map, shroud_edges, shroud_edges_shadow, screen);

  mouse.draw(screen);

  SDL_Flip(screen);
}

void Game::updateState() {
  keyboard.updateState();
  mouse.updateState();
  map_camera->updateState();

  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    (*it)->updateState();
  }
}

int Game::cleanup() {
  delete map_camera;
  delete unitRepository;
  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    delete *it;
  }
  units.clear();
  SDL_FreeSurface(screen);
  SDL_FreeSurface(terrain);
  SDL_FreeSurface(shroud_edges);
  SDL_FreeSurface(shroud_edges_shadow);
  SDL_Quit();
  return 0;
}

void Game::deselectAllUnits() {
  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    (*it)->unselect();
  }
}

<commit_msg>revert order of drawing so we draw the air unit after ground unit, fixing this feature, which was broken by a boyscout<commit_after>#include <iostream>

#include "SDL/SDL.h"
#include "SDL_image.h"
#include "SDL_gfxPrimitives.h"
#include "point.h"
#include "map.h"
#include "game.h"
#include "surface.h"
#include "eventfactory.h"

using namespace std;

Game::Game() {
  playing=true;
  screen=NULL;
  terrain=NULL;
  map_camera=NULL;
}

int Game::execute() {
  if (!init()) {
    cerr << "Errors occured when starting the game. Stopping." << endl;
    return 1;
  }

  SDL_Event event;

  while(playing) {
    SDL_PumpEvents();
    while(SDL_PollEvent(&event)) {
      onEvent(&event);
    }

    updateState();
    render();
    // SDL rest?
  }

  return cleanup();
}

int Game::init() {
  if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
    return false;
  }

  screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
  if(screen == NULL) {
     return false;
  }

  int flags = IMG_INIT_JPG | IMG_INIT_PNG;
  int initted=IMG_Init(flags);
  if( initted & flags != flags) {
    cout << "could not init SDL_Image" << endl;
    cout << "Reason: " << IMG_GetError() << endl;
    return false;
  }

  terrain = Surface::load("graphics/terrain.png");

  if (terrain == NULL) {
    cout << "Failed to read graphics/terrain.png data" << endl;
    return false;
  }

  shroud_edges = Surface::load("graphics/shroud_edges.bmp");

  if (shroud_edges == NULL) {
    cout << "Failed to read graphics/shroud_edges.bmp data" << endl;
    return false;
  }

  shroud_edges_shadow = Surface::load("graphics/shroud_edges_shadow.bmp");

  if (shroud_edges_shadow == NULL) {
    cout << "Failed to read graphics/shroud_edges_shadow.bmp data" << endl;
    return false;
  }

  SDL_ShowCursor(0);
  mouse.init(screen);

  map_camera = new MapCamera(0, 0, screen, &map);
  map.load("maps/4PL_Mountains.ini");
  unitRepository = new UnitRepository(&map);

  Unit* frigate = unitRepository->create(UNIT_FRIGATE, HOUSE_SARDAUKAR, 64, 64, 10);
  units.push_back(frigate);

  Unit* trike1 = unitRepository->create(UNIT_TRIKE, HOUSE_ATREIDES, 256, 256, 3);
  units.push_back(trike1);

  Unit* trike2 = unitRepository->create(UNIT_TRIKE, HOUSE_ATREIDES, 448, 448, 3);
  units.push_back(trike2);

  return true;
}

void Game::onEvent(SDL_Event* event) {
  if(event->type == SDL_QUIT) {
    playing = false;
  }

  mouse.onEvent(event);
  keyboard.onEvent(event);

  map_camera->onEvent(event);

  if (event->type == SDL_USEREVENT) {
    if (event->user.code == D2TM_SELECT) {
      D2TMSelectStruct *s = static_cast<D2TMSelectStruct*>(event->user.data1);

      Point p = map_camera->toWorldCoordinates(s->screen_position);

      if (mouse.is_pointing()) {
        Unit* selected_unit = NULL;
        for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
          if ((*it)->is_point_within(p)) {
            selected_unit = *it;
            break;
          }
        }

        if (selected_unit != NULL) {
          deselectAllUnits();
          selected_unit->select();
          mouse.state_order_move();
        }
      }

      delete s;
    } else if (event->user.code == D2TM_DESELECT) {
      mouse.state_pointing();
      deselectAllUnits();
    } else if (event->user.code == D2TM_BOX_SELECT) {
      D2TMBoxSelectStruct *s = static_cast<D2TMBoxSelectStruct*>(event->user.data1);

      Rectangle rectangle = map_camera->toWorldCoordinates(s->rectangle);

      if (mouse.is_pointing()) {
        mouse.state_pointing();

        deselectAllUnits();
        for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
          if ((*it)->is_within(rectangle)) {
            (*it)->select();
            mouse.state_order_move();
          }
        }
      }

      delete s;
    } else if (event->user.code == D2TM_MOVE_UNIT) {
      D2TMMoveUnitStruct *s = static_cast<D2TMMoveUnitStruct*>(event->user.data1);
      Point p = map_camera->toWorldCoordinates(s->screen_position);

      for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
        if ((*it)->is_selected()) {
          (*it)->order_move(p);
        }
      }

      delete s;
    }

  }

}

void Game::render() {
  SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));

  map_camera->draw(&map, terrain, screen);

  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    if ((*it)->is_on_ground_layer()) map_camera->draw(*it, screen);
  }

  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    if ((*it)->is_on_air_layer()) map_camera->draw(*it, screen);
  }

  map_camera->drawShroud(&map, shroud_edges, shroud_edges_shadow, screen);

  mouse.draw(screen);

  SDL_Flip(screen);
}

void Game::updateState() {
  keyboard.updateState();
  mouse.updateState();
  map_camera->updateState();

  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    (*it)->updateState();
  }
}

int Game::cleanup() {
  delete map_camera;
  delete unitRepository;
  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    delete *it;
  }
  units.clear();
  SDL_FreeSurface(screen);
  SDL_FreeSurface(terrain);
  SDL_FreeSurface(shroud_edges);
  SDL_FreeSurface(shroud_edges_shadow);
  SDL_Quit();
  return 0;
}

void Game::deselectAllUnits() {
  for (vector<Unit*>::iterator it = units.begin(); it != units.end(); ++it) {
    (*it)->unselect();
  }
}

<|endoftext|>


<commit_before>#include "game.h"
#include <stdio.h>
#include "game_of_life.cpp"
#include <math.h>

#define MIN_FRAMERATE 0
#define MAX_FRAMERATE 30

#define BOARD_SIZE 500

typedef struct game_state
{
    memory_arena arena;

    int32 current_generation[BOARD_SIZE*BOARD_SIZE];
    int32 prev_generation[BOARD_SIZE*BOARD_SIZE];

    int32 rows;
    int32 cols;

    real32 cell_height;
    real32 cell_width;

    real32 camera_x;
    real32 camera_y;

    real32 min_camera_x;
    real32 max_camera_x;
    real32 min_camera_y;
    real32 max_camera_y;

    int32 framecount;
    int32 framerate;

    bool32 paused;

    uint64 total_time;
} game_state;

internal uint32
round_real32_to_int32(real32 value)
{
    return((int32)value + 0.5f);
}

internal uint32
round_real32_to_uint32(real32 value)
{
    return((uint32)value + 0.5f);
}

internal void
draw_rectangle_alpha(game_offscreen_buffer *buffer,
               real32 x, real32 y, real32 width, real32 height,
               real32 r, real32 g, real32 b, real32 a)
{
    int32 min_x = round_real32_to_int32(x);
    int32 min_y = round_real32_to_int32(y);
    int32 max_x = round_real32_to_int32(x + width);
    int32 max_y = round_real32_to_int32(y + height);

    if(min_x < 0)
    {
        min_x = 0;
    }

    if(min_y < 0)
    {
        min_y = 0;
    }

    if(max_x > buffer->width)
    {
        max_x = buffer->width;
    }

    if(max_y > buffer->height)
    {
        max_y = buffer->height;
    }

    uint8 *row = ((uint8 *)buffer->memory +
                 min_x*buffer->bytes_per_pixel +
                 min_y*buffer->pitch);

    for(int iterY = min_y;
        iterY < max_y;
       ++iterY)
    {
        uint32 *pixel = (uint32 *)row;
        for(int iterX = min_x;
            iterX < max_x;
            ++iterX)
        {
            real32 dest_r = (real32)((*pixel >> 16) & 0xFF);
            real32 dest_g = (real32)((*pixel >>  8) & 0xFF);
            real32 dest_b = (real32)((*pixel >>  0) & 0xFF);

            real32 new_r = (1.0f - a)*dest_r + a*r;
            real32 new_g = (1.0f - a)*dest_g + a*g;
            real32 new_b = (1.0f - a)*dest_b + a*b;

            uint32 color = ((round_real32_to_uint32(new_r * 255.0f) << 16) |
                            (round_real32_to_uint32(new_g * 255.0f) << 8) |
                            (round_real32_to_uint32(new_b * 255.0f) << 0));

            *pixel++ = color;
        }

        row += buffer->pitch;
    }
}

internal void
draw_rectangle(game_offscreen_buffer *buffer,
               real32 x, real32 y, real32 width, real32 height,
               real32 r, real32 g, real32 b)
{
    draw_rectangle_alpha(buffer,
                         x, y,
                         width, height,
                         r, g, b, 1.0f);
}

internal void
constrain_camera(game_state *state, game_offscreen_buffer *buffer)
{
    real32 min_camera_x = 0;
    real32 max_camera_x = state->rows*state->cell_width - buffer->width;
    real32 min_camera_y = 0;
    real32 max_camera_y = state->rows*state->cell_height - buffer->height;

    state->camera_x = MIN(MAX(state->camera_x, min_camera_x), max_camera_x);
    state->camera_y = MIN(MAX(state->camera_y, min_camera_y), max_camera_y);
}

extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender)
{
    assert(sizeof(game_state) <= memory->permanent_storage_size);

    game_state *state = (game_state *)memory->permanent_storage;

    if(!memory->is_initialized)
    {
        memory->is_initialized = true;

        initialize_arena(&state->arena, memory->permanent_storage_size - sizeof(game_state),
        (uint8 *)memory->permanent_storage + sizeof(game_state));

        state->rows = BOARD_SIZE;
        state->cols = BOARD_SIZE;

        state->cell_width = 30.0f;
        state->cell_height = 30.0f;

        // glider
        state->current_generation[0*state->cols + 1] = 1;
        state->current_generation[1*state->cols + 2] = 1;
        state->current_generation[2*state->cols + 0] = 1;
        state->current_generation[2*state->cols + 1] = 1;
        state->current_generation[2*state->cols + 2] = 1;

        state->current_generation[5*state->cols + 11] = 1;
        state->current_generation[6*state->cols + 12] = 1;
        state->current_generation[7*state->cols + 10] = 1;
        state->current_generation[7*state->cols + 11] = 1;
        state->current_generation[7*state->cols + 12] = 1;

        state->framecount = 0;
        state->framerate = 5;
    }

    for(int i = 0;
        i < array_count(input->controllers);
        ++i)
    {
        game_controller_input *controller = &input->controllers[i];
        if(controller->back.ended_down)
        {
            state->paused = true;
        }

        if(controller->start.ended_down)
        {
            state->paused = false;
        }

        if(controller->action_up.ended_down)
        {
            state->framerate = MAX(state->framerate-1, MIN_FRAMERATE);
        }

        if(controller->action_down.ended_down)
        {
            state->framerate = MIN(state->framerate+1, MAX_FRAMERATE);
        }

        if(controller->move_up.ended_down)
        {
            state->camera_y -= 15.0f;
        }

        if(controller->move_down.ended_down)
        {
            state->camera_y += 15.0f;
        }

        if(controller->move_left.ended_down)
        {
            state->camera_x -= 15.0f;
        }

        if(controller->move_right.ended_down)
        {
            state->camera_x += 15.0f;
        }
    }

    constrain_camera(state, buffer);

    int32 mouse_x = (int32)((input->mouse_x + state->camera_x) / state->cell_width);
    int32 mouse_y = (int32)((input->mouse_y + state->camera_y) / state->cell_height);

    if(input->MouseLeft.ended_down)
    {
        if(mouse_x >= 0 &&
           mouse_x < state->cols &&
           mouse_y >= 0 &&
           mouse_y < state->rows)
        {
            set_board_value(state->current_generation, state->rows, state->cols,
                            mouse_x, mouse_y, 1);
        }
    }

    // NOTE(partkyle): update size based on mouse wheel
    state->cell_height = MAX(state->cell_height + input->mouse_z, 2);
    state->cell_width = MAX(state->cell_width + input->mouse_z, 2);

    if(!state->paused)
    {
        if(++state->framecount > state->framerate)
        {
            state->framecount = 0;

            swap(state->current_generation, state->prev_generation);

            next_generation(state->current_generation, state->prev_generation, state->rows, state->cols);
        }
    }

    // DEBUG layer to show edges
    draw_rectangle(buffer, 0, 0, buffer->width, buffer->height, 1.0f, 0.0f, 1.0f);

    real32 alpha_value = 1.0f;
    if(state->paused)
    {
        state->total_time += 1;
        alpha_value = MIN(0.33f*((real32)sin((real32)state->total_time / 25.0f) + 1.0f) + 0.25f, 1.0f);
    }

    for (int y = 0; y < BOARD_SIZE; ++y)
    {
        for (int x = 0; x < BOARD_SIZE; ++x)
        {
            int32 cell = get_board_value(state->current_generation, state->rows, state->cols, x, y);

            real32 cell_pos_x = x*state->cell_width - state->camera_x;
            real32 cell_pos_y = y*state->cell_height - state->camera_y;

#if 0
            // grid lines
            draw_rectangle(buffer,
                           cell_pos_x, cell_pos_y,
                           state->cell_width, state->cell_height,
                           0.5f, 0.5f, 0.5f);
#endif

            // dead cells by default (used for alpha)
            draw_rectangle(buffer,
                           cell_pos_x, cell_pos_y,
                           state->cell_width, state->cell_height,
                           0.0f, 0.0f, 0.0f);

            if(cell)
            {
                real32 r = 1.0f - (real32)state->framerate / (real32)MAX_FRAMERATE;
                real32 g = 0.4f;
                real32 b = (real32)state->framerate / (real32)MAX_FRAMERATE;

                // live cells
                draw_rectangle_alpha(buffer,
                                     1+cell_pos_x, 1+cell_pos_y,
                                     state->cell_width-1, state->cell_height-1,
                                     r, g, b, alpha_value);
            }
#if 0
            // prev gen dots
            int32 prev_cell = get_board_value(state->prev_generation,
                                              state->rows, state->cols,
                                              x, y);
            if(prev_cell)
            {
                real32 r = 1.0f;
                real32 g = 1.0f;
                real32 b = 1.0f;

                draw_rectangle(buffer,
                               cell_pos_x+(state->cell_width*0.45f), cell_pos_y+(state->cell_height*0.5f),
                               1, 1,
                               r, g, b);
            }
#endif
        }
    }

    return(0);
}
<commit_msg>update MAX FRAMERATE<commit_after>#include "game.h"
#include <stdio.h>
#include "game_of_life.cpp"
#include <math.h>

#define MIN_FRAMERATE 0
#define MAX_FRAMERATE 60

#define BOARD_SIZE 500

typedef struct game_state
{
    memory_arena arena;

    int32 current_generation[BOARD_SIZE*BOARD_SIZE];
    int32 prev_generation[BOARD_SIZE*BOARD_SIZE];

    int32 rows;
    int32 cols;

    real32 cell_height;
    real32 cell_width;

    real32 camera_x;
    real32 camera_y;

    int32 framecount;
    int32 framerate;

    bool32 paused;

    uint64 total_time;
} game_state;

internal uint32
round_real32_to_int32(real32 value)
{
    return((int32)value + 0.5f);
}

internal uint32
round_real32_to_uint32(real32 value)
{
    return((uint32)value + 0.5f);
}

internal void
draw_rectangle_alpha(game_offscreen_buffer *buffer,
               real32 x, real32 y, real32 width, real32 height,
               real32 r, real32 g, real32 b, real32 a)
{
    int32 min_x = round_real32_to_int32(x);
    int32 min_y = round_real32_to_int32(y);
    int32 max_x = round_real32_to_int32(x + width);
    int32 max_y = round_real32_to_int32(y + height);

    if(min_x < 0)
    {
        min_x = 0;
    }

    if(min_y < 0)
    {
        min_y = 0;
    }

    if(max_x > buffer->width)
    {
        max_x = buffer->width;
    }

    if(max_y > buffer->height)
    {
        max_y = buffer->height;
    }

    uint8 *row = ((uint8 *)buffer->memory +
                 min_x*buffer->bytes_per_pixel +
                 min_y*buffer->pitch);

    for(int iterY = min_y;
        iterY < max_y;
       ++iterY)
    {
        uint32 *pixel = (uint32 *)row;
        for(int iterX = min_x;
            iterX < max_x;
            ++iterX)
        {
            real32 dest_r = (real32)((*pixel >> 16) & 0xFF);
            real32 dest_g = (real32)((*pixel >>  8) & 0xFF);
            real32 dest_b = (real32)((*pixel >>  0) & 0xFF);

            real32 new_r = (1.0f - a)*dest_r + a*r;
            real32 new_g = (1.0f - a)*dest_g + a*g;
            real32 new_b = (1.0f - a)*dest_b + a*b;

            uint32 color = ((round_real32_to_uint32(new_r * 255.0f) << 16) |
                            (round_real32_to_uint32(new_g * 255.0f) << 8) |
                            (round_real32_to_uint32(new_b * 255.0f) << 0));

            *pixel++ = color;
        }

        row += buffer->pitch;
    }
}

internal void
draw_rectangle(game_offscreen_buffer *buffer,
               real32 x, real32 y, real32 width, real32 height,
               real32 r, real32 g, real32 b)
{
    draw_rectangle_alpha(buffer,
                         x, y,
                         width, height,
                         r, g, b, 1.0f);
}

internal void
constrain_camera(game_state *state, game_offscreen_buffer *buffer)
{
    real32 min_camera_x = 0;
    real32 max_camera_x = state->rows*state->cell_width - buffer->width;
    real32 min_camera_y = 0;
    real32 max_camera_y = state->rows*state->cell_height - buffer->height;

    state->camera_x = MIN(MAX(state->camera_x, min_camera_x), max_camera_x);
    state->camera_y = MIN(MAX(state->camera_y, min_camera_y), max_camera_y);
}

extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender)
{
    assert(sizeof(game_state) <= memory->permanent_storage_size);

    game_state *state = (game_state *)memory->permanent_storage;

    if(!memory->is_initialized)
    {
        memory->is_initialized = true;

        initialize_arena(&state->arena, memory->permanent_storage_size - sizeof(game_state),
        (uint8 *)memory->permanent_storage + sizeof(game_state));

        state->rows = BOARD_SIZE;
        state->cols = BOARD_SIZE;

        state->cell_width = 30.0f;
        state->cell_height = 30.0f;

        // glider
        state->current_generation[0*state->cols + 1] = 1;
        state->current_generation[1*state->cols + 2] = 1;
        state->current_generation[2*state->cols + 0] = 1;
        state->current_generation[2*state->cols + 1] = 1;
        state->current_generation[2*state->cols + 2] = 1;

        state->current_generation[5*state->cols + 11] = 1;
        state->current_generation[6*state->cols + 12] = 1;
        state->current_generation[7*state->cols + 10] = 1;
        state->current_generation[7*state->cols + 11] = 1;
        state->current_generation[7*state->cols + 12] = 1;

        state->framecount = 0;
        state->framerate = 5;
    }

    for(int i = 0;
        i < array_count(input->controllers);
        ++i)
    {
        game_controller_input *controller = &input->controllers[i];
        if(controller->back.ended_down)
        {
            state->paused = true;
        }

        if(controller->start.ended_down)
        {
            state->paused = false;
        }

        if(controller->action_up.ended_down)
        {
            state->framerate = MAX(state->framerate-1, MIN_FRAMERATE);
        }

        if(controller->action_down.ended_down)
        {
            state->framerate = MIN(state->framerate+1, MAX_FRAMERATE);
        }

        if(controller->move_up.ended_down)
        {
            state->camera_y -= 15.0f;
        }

        if(controller->move_down.ended_down)
        {
            state->camera_y += 15.0f;
        }

        if(controller->move_left.ended_down)
        {
            state->camera_x -= 15.0f;
        }

        if(controller->move_right.ended_down)
        {
            state->camera_x += 15.0f;
        }
    }

    constrain_camera(state, buffer);

    int32 mouse_x = (int32)((input->mouse_x + state->camera_x) / state->cell_width);
    int32 mouse_y = (int32)((input->mouse_y + state->camera_y) / state->cell_height);

    if(input->MouseLeft.ended_down)
    {
        if(mouse_x >= 0 &&
           mouse_x < state->cols &&
           mouse_y >= 0 &&
           mouse_y < state->rows)
        {
            set_board_value(state->current_generation, state->rows, state->cols,
                            mouse_x, mouse_y, 1);
        }
    }

    // NOTE(partkyle): update size based on mouse wheel
    state->cell_height = MAX(state->cell_height + input->mouse_z, 2);
    state->cell_width = MAX(state->cell_width + input->mouse_z, 2);

    if(!state->paused)
    {
        if(++state->framecount > state->framerate)
        {
            state->framecount = 0;

            swap(state->current_generation, state->prev_generation);

            next_generation(state->current_generation, state->prev_generation, state->rows, state->cols);
        }
    }

    // DEBUG layer to show edges
    draw_rectangle(buffer, 0, 0, buffer->width, buffer->height, 1.0f, 0.0f, 1.0f);

    real32 alpha_value = 1.0f;
    if(state->paused)
    {
        state->total_time += 1;
        alpha_value = MIN(0.33f*((real32)sin((real32)state->total_time / 25.0f) + 1.0f) + 0.25f, 1.0f);
    }

    for (int y = 0; y < BOARD_SIZE; ++y)
    {
        for (int x = 0; x < BOARD_SIZE; ++x)
        {
            int32 cell = get_board_value(state->current_generation, state->rows, state->cols, x, y);

            real32 cell_pos_x = x*state->cell_width - state->camera_x;
            real32 cell_pos_y = y*state->cell_height - state->camera_y;

#if 0
            // grid lines
            draw_rectangle(buffer,
                           cell_pos_x, cell_pos_y,
                           state->cell_width, state->cell_height,
                           0.5f, 0.5f, 0.5f);
#endif

            // dead cells by default (used for alpha)
            draw_rectangle(buffer,
                           cell_pos_x, cell_pos_y,
                           state->cell_width, state->cell_height,
                           0.0f, 0.0f, 0.0f);

            if(cell)
            {
                real32 r = 1.0f - (real32)state->framerate / (real32)MAX_FRAMERATE;
                real32 g = 0.4f;
                real32 b = (real32)state->framerate / (real32)MAX_FRAMERATE;

                // live cells
                draw_rectangle_alpha(buffer,
                                     1+cell_pos_x, 1+cell_pos_y,
                                     state->cell_width-1, state->cell_height-1,
                                     r, g, b, alpha_value);
            }
#if 0
            // prev gen dots
            int32 prev_cell = get_board_value(state->prev_generation,
                                              state->rows, state->cols,
                                              x, y);
            if(prev_cell)
            {
                real32 r = 1.0f;
                real32 g = 1.0f;
                real32 b = 1.0f;

                draw_rectangle(buffer,
                               cell_pos_x+(state->cell_width*0.45f), cell_pos_y+(state->cell_height*0.5f),
                               1, 1,
                               r, g, b);
            }
#endif
        }
    }

    return(0);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: AxisWrapper.hxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef CHART_AXISWRAPPER_HXX
#define CHART_AXISWRAPPER_HXX

#include "WrappedPropertySet.hxx"
#include "ReferenceSizePropertyProvider.hxx"
#include "ServiceMacros.hxx"
#include <cppuhelper/implbase4.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <com/sun/star/chart2/XAxis.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>

#include <boost/shared_ptr.hpp>

namespace chart
{

namespace wrapper
{

class Chart2ModelContact;

class AxisWrapper : public ::cppu::ImplInheritanceHelper4<
                      WrappedPropertySet
                    , com::sun::star::drawing::XShape
                    , com::sun::star::lang::XComponent
                    , com::sun::star::lang::XServiceInfo
                    , com::sun::star::util::XNumberFormatsSupplier
                    >
                    , public ReferenceSizePropertyProvider
{
public:
    enum tAxisType
    {
        X_AXIS,
        Y_AXIS,
        Z_AXIS,
        SECOND_X_AXIS,
        SECOND_Y_AXIS
    };

    AxisWrapper( tAxisType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
    virtual ~AxisWrapper();

    static void getDimensionAndMainAxisBool( tAxisType eType, sal_Int32& rnDimensionIndex, sal_Bool& rbMainAxis );

    /// XServiceInfo declarations
    APPHELPER_XSERVICEINFO_DECL()

    //ReferenceSizePropertyProvider
    virtual void setCurrentSizeAsReference();
    virtual ::com::sun::star::uno::Any getReferenceSize();
    virtual ::com::sun::star::awt::Size getCurrentSizeForReference();

    // ____ XComponent ____
    virtual void SAL_CALL dispose()
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference<
                                            ::com::sun::star::lang::XEventListener >& xListener )
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference<
                                               ::com::sun::star::lang::XEventListener >& aListener )
        throw (::com::sun::star::uno::RuntimeException);

    // ____ XShape ____
    virtual ::com::sun::star::awt::Point SAL_CALL getPosition()
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setPosition( const ::com::sun::star::awt::Point& aPosition )
        throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::awt::Size SAL_CALL getSize()
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setSize( const ::com::sun::star::awt::Size& aSize )
        throw (::com::sun::star::beans::PropertyVetoException,
               ::com::sun::star::uno::RuntimeException);

    // ____ XShapeDescriptor (base of XShape) ____
    virtual ::rtl::OUString SAL_CALL getShapeType()
        throw (::com::sun::star::uno::RuntimeException);

    // ____ XNumberFormatsSupplier ____
    virtual ::com::sun::star::uno::Reference<
                ::com::sun::star::beans::XPropertySet > SAL_CALL getNumberFormatSettings()
            throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference<
                ::com::sun::star::util::XNumberFormats > SAL_CALL getNumberFormats()
            throw (::com::sun::star::uno::RuntimeException);

protected:
    // ____ WrappedPropertySet ____
    virtual const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& getPropertySequence();
    virtual const std::vector< WrappedProperty* > createWrappedProperties();
    virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getInnerPropertySet();

private: //methods
    ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis > getAxis();

private: //member
    ::boost::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
    ::cppu::OInterfaceContainerHelper           m_aEventListenerContainer;

    tAxisType           m_eType;
    ::com::sun::star::uno::Any m_aTemporaryHelpStepValue;
};

} //  namespace wrapper
} //  namespace chart

// CHART_AXISWRAPPER_HXX
#endif
<commit_msg>INTEGRATION: CWS chart27 (1.5.30); FILE MERGED 2008/06/24 11:08:44 iha 1.5.30.1: #i90504# Minor interval marks are not saved and loeaded correctly<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: AxisWrapper.hxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef CHART_AXISWRAPPER_HXX
#define CHART_AXISWRAPPER_HXX

#include "WrappedPropertySet.hxx"
#include "ReferenceSizePropertyProvider.hxx"
#include "ServiceMacros.hxx"
#include <cppuhelper/implbase4.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <com/sun/star/chart2/XAxis.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>

#include <boost/shared_ptr.hpp>

namespace chart
{

namespace wrapper
{

class Chart2ModelContact;

class AxisWrapper : public ::cppu::ImplInheritanceHelper4<
                      WrappedPropertySet
                    , com::sun::star::drawing::XShape
                    , com::sun::star::lang::XComponent
                    , com::sun::star::lang::XServiceInfo
                    , com::sun::star::util::XNumberFormatsSupplier
                    >
                    , public ReferenceSizePropertyProvider
{
public:
    enum tAxisType
    {
        X_AXIS,
        Y_AXIS,
        Z_AXIS,
        SECOND_X_AXIS,
        SECOND_Y_AXIS
    };

    AxisWrapper( tAxisType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
    virtual ~AxisWrapper();

    static void getDimensionAndMainAxisBool( tAxisType eType, sal_Int32& rnDimensionIndex, sal_Bool& rbMainAxis );

    /// XServiceInfo declarations
    APPHELPER_XSERVICEINFO_DECL()

    //ReferenceSizePropertyProvider
    virtual void setCurrentSizeAsReference();
    virtual ::com::sun::star::uno::Any getReferenceSize();
    virtual ::com::sun::star::awt::Size getCurrentSizeForReference();

    // ____ XComponent ____
    virtual void SAL_CALL dispose()
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference<
                                            ::com::sun::star::lang::XEventListener >& xListener )
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference<
                                               ::com::sun::star::lang::XEventListener >& aListener )
        throw (::com::sun::star::uno::RuntimeException);

    // ____ XShape ____
    virtual ::com::sun::star::awt::Point SAL_CALL getPosition()
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setPosition( const ::com::sun::star::awt::Point& aPosition )
        throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::awt::Size SAL_CALL getSize()
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setSize( const ::com::sun::star::awt::Size& aSize )
        throw (::com::sun::star::beans::PropertyVetoException,
               ::com::sun::star::uno::RuntimeException);

    // ____ XShapeDescriptor (base of XShape) ____
    virtual ::rtl::OUString SAL_CALL getShapeType()
        throw (::com::sun::star::uno::RuntimeException);

    // ____ XNumberFormatsSupplier ____
    virtual ::com::sun::star::uno::Reference<
                ::com::sun::star::beans::XPropertySet > SAL_CALL getNumberFormatSettings()
            throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference<
                ::com::sun::star::util::XNumberFormats > SAL_CALL getNumberFormats()
            throw (::com::sun::star::uno::RuntimeException);

protected:
    // ____ WrappedPropertySet ____
    virtual const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& getPropertySequence();
    virtual const std::vector< WrappedProperty* > createWrappedProperties();
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getInnerPropertySet();

private: //methods
    ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis > getAxis();

private: //member
    ::boost::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
    ::cppu::OInterfaceContainerHelper           m_aEventListenerContainer;

    tAxisType           m_eType;
    ::com::sun::star::uno::Any m_aTemporaryHelpStepValue;
};

} //  namespace wrapper
} //  namespace chart

// CHART_AXISWRAPPER_HXX
#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ViewElementListProvider.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: vg $ $Date: 2007-05-22 17:57:30 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _CHART2_VIEWELEMENTLISTPROVIDER_HXX
#define _CHART2_VIEWELEMENTLISTPROVIDER_HXX

#ifndef _XTABLE_HXX
#include <svx/xtable.hxx>
#endif
#ifndef _SVDPAGE_HXX
#include <svx/svdpage.hxx>
#endif

class FontList;

//.............................................................................
namespace chart
{
//.............................................................................

class DrawModelWrapper;

class ViewElementListProvider
{
public:
    ViewElementListProvider( DrawModelWrapper* pDrawModelWrapper );
    virtual ~ViewElementListProvider();

    XColorTable*    GetColorTable() const;
    XDashList*      GetDashList() const;
    XLineEndList*   GetLineEndList() const;
    XGradientList*  GetGradientList() const;
    XHatchList*     GetHatchList() const;
    XBitmapList*    GetBitmapList() const;

    //create chartspecific symbols for linecharts
    SdrObjList*     GetSymbolList() const;
    Graphic         GetSymbolGraphic( sal_Int32 nStandardSymbol, const SfxItemSet* pSymbolShapeProperties ) const;

    FontList*       getFontList() const;
    //SfxPrinter*   getPrinter();

private:
    DrawModelWrapper*   m_pDrawModelWrapper;
    mutable FontList*   m_pFontList;
};

//.............................................................................
} //namespace chart
//.............................................................................
#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.4.126); FILE MERGED 2008/04/01 15:04:07 thb 1.4.126.2: #i85898# Stripping all external header guards 2008/03/28 16:43:45 rt 1.4.126.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: ViewElementListProvider.hxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _CHART2_VIEWELEMENTLISTPROVIDER_HXX
#define _CHART2_VIEWELEMENTLISTPROVIDER_HXX

#include <svx/xtable.hxx>
#include <svx/svdpage.hxx>

class FontList;

//.............................................................................
namespace chart
{
//.............................................................................

class DrawModelWrapper;

class ViewElementListProvider
{
public:
    ViewElementListProvider( DrawModelWrapper* pDrawModelWrapper );
    virtual ~ViewElementListProvider();

    XColorTable*    GetColorTable() const;
    XDashList*      GetDashList() const;
    XLineEndList*   GetLineEndList() const;
    XGradientList*  GetGradientList() const;
    XHatchList*     GetHatchList() const;
    XBitmapList*    GetBitmapList() const;

    //create chartspecific symbols for linecharts
    SdrObjList*     GetSymbolList() const;
    Graphic         GetSymbolGraphic( sal_Int32 nStandardSymbol, const SfxItemSet* pSymbolShapeProperties ) const;

    FontList*       getFontList() const;
    //SfxPrinter*   getPrinter();

private:
    DrawModelWrapper*   m_pDrawModelWrapper;
    mutable FontList*   m_pFontList;
};

//.............................................................................
} //namespace chart
//.............................................................................
#endif
<|endoftext|>


<commit_before>/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
#include <eos/chain/exceptions.hpp>
#include <fc/io/raw.hpp>
#include <fc/bitutil.hpp>
#include <fc/smart_ref_impl.hpp>
#include <algorithm>

#include <boost/range/adaptor/transformed.hpp>

namespace eosio { namespace chain {

digest_type transaction_digest(const transaction& t) {
   digest_type::encoder enc;
   fc::raw::pack( enc, t );
   return enc.result();
}

void transaction_set_reference_block(transaction& t, const block_id_type& reference_block) {
   t.ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]);
   t.ref_block_prefix = reference_block._hash[1];
}

bool transaction_verify_reference_block(const transaction& t, const block_id_type& reference_block) {
   return t.ref_block_num == (decltype(t.ref_block_num))fc::endian_reverse_u32(reference_block._hash[0]) &&
          t.ref_block_prefix == (decltype(t.ref_block_prefix))reference_block._hash[1];
}

digest_type signed_transaction::sig_digest( const chain_id_type& chain_id )const {
   digest_type::encoder enc;
   fc::raw::pack( enc, chain_id );
   fc::raw::pack( enc, static_cast<const types::transaction&>(*this) );
   return enc.result();
}

eosio::chain::transaction_id_type signed_transaction::id() const {
   auto h = transaction_digest(*this);
   transaction_id_type result;
   memcpy(result._hash, h._hash, std::min(sizeof(result), sizeof(h)));
   return result;
}

const signature_type& eosio::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id) {
   signatures.push_back(key.sign_compact(sig_digest(chain_id)));
   return signatures.back();
}

signature_type eosio::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const {
   return key.sign_compact(sig_digest(chain_id));
}

flat_set<public_key_type> signed_transaction::get_signature_keys( const chain_id_type& chain_id )const
{ try {
   using boost::adaptors::transformed;
   auto SigToKey = transformed([digest = sig_digest(chain_id)](const fc::ecc::compact_signature& signature) {
      return public_key_type(fc::ecc::public_key(signature, digest));
   });
   auto keyRange = signatures | SigToKey;
   return {keyRange.begin(), keyRange.end()};
   } FC_CAPTURE_AND_RETHROW() }

eosio::chain::digest_type signed_transaction::merkle_digest() const {
   digest_type::encoder enc;
   fc::raw::pack(enc, static_cast<const types::transaction&>(*this));
   return enc.result();
}

digest_type generated_transaction::merkle_digest() const {
   digest_type::encoder enc;
   fc::raw::pack(enc, *this);
   return enc.result();
}

} } // eosio::chain
<commit_msg>Create key recovery cache on transactions<commit_after>/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
#include <eos/chain/exceptions.hpp>
#include <fc/io/raw.hpp>
#include <fc/bitutil.hpp>
#include <fc/smart_ref_impl.hpp>
#include <algorithm>

#include <boost/range/adaptor/transformed.hpp>

namespace eosio { namespace chain {

digest_type transaction_digest(const transaction& t) {
   digest_type::encoder enc;
   fc::raw::pack( enc, t );
   return enc.result();
}

void transaction_set_reference_block(transaction& t, const block_id_type& reference_block) {
   t.ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]);
   t.ref_block_prefix = reference_block._hash[1];
}

bool transaction_verify_reference_block(const transaction& t, const block_id_type& reference_block) {
   return t.ref_block_num == (decltype(t.ref_block_num))fc::endian_reverse_u32(reference_block._hash[0]) &&
          t.ref_block_prefix == (decltype(t.ref_block_prefix))reference_block._hash[1];
}

digest_type signed_transaction::sig_digest( const chain_id_type& chain_id )const {
   digest_type::encoder enc;
   fc::raw::pack( enc, chain_id );
   fc::raw::pack( enc, static_cast<const types::transaction&>(*this) );
   return enc.result();
}

eosio::chain::transaction_id_type signed_transaction::id() const {
   auto h = transaction_digest(*this);
   transaction_id_type result;
   memcpy(result._hash, h._hash, std::min(sizeof(result), sizeof(h)));
   return result;
}

const signature_type& eosio::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id) {
   signatures.push_back(key.sign_compact(sig_digest(chain_id)));
   return signatures.back();
}

signature_type eosio::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const {
   return key.sign_compact(sig_digest(chain_id));
}

flat_set<public_key_type> signed_transaction::get_signature_keys( const chain_id_type& chain_id )const
{ try {
   using boost::adaptors::transformed;

   ///Warning: This "leaks" as we never clean up old entries in the cache. Next release will have a more
   //          proper implementation.
   static std::map<transaction_id_type, flat_set<public_key_type>> pub_key_cache;
   std::map<transaction_id_type, flat_set<public_key_type>>::iterator it = pub_key_cache.find(id());
   if(it != pub_key_cache.end())
      return it->second;

   auto SigToKey = transformed([digest = sig_digest(chain_id)](const fc::ecc::compact_signature& signature) {
      return public_key_type(fc::ecc::public_key(signature, digest));
   });
   auto keyRange = signatures | SigToKey;
   it = pub_key_cache.emplace(id(), flat_set<public_key_type>{keyRange.begin(), keyRange.end()}).first;
   return it->second;
   } FC_CAPTURE_AND_RETHROW() }

eosio::chain::digest_type signed_transaction::merkle_digest() const {
   digest_type::encoder enc;
   fc::raw::pack(enc, static_cast<const types::transaction&>(*this));
   return enc.result();
}

digest_type generated_transaction::merkle_digest() const {
   digest_type::encoder enc;
   fc::raw::pack(enc, *this);
   return enc.result();
}

} } // eosio::chain
<|endoftext|>


<commit_before>#include <bts/net/core_messages.hpp>

namespace bts { namespace net {

  const core_message_type_enum item_ids_inventory_message::type            = core_message_type_enum::item_ids_inventory_message_type;
  const core_message_type_enum blockchain_item_ids_inventory_message::type = core_message_type_enum::blockchain_item_ids_inventory_message_type;
  const core_message_type_enum fetch_blockchain_item_ids_message::type     = core_message_type_enum::fetch_blockchain_item_ids_message_type;
  const core_message_type_enum fetch_items_message::type                   = core_message_type_enum::fetch_items_message_type;
  const core_message_type_enum item_not_available_message::type            = core_message_type_enum::item_not_available_message_type;
  const core_message_type_enum hello_message::type                         = core_message_type_enum::hello_message_type;
  const core_message_type_enum connection_accepted_message::type           = core_message_type_enum::connection_accepted_message_type;
  const core_message_type_enum connection_rejected_message::type           = core_message_type_enum::connection_rejected_message_type;
  const core_message_type_enum address_request_message::type               = core_message_type_enum::address_request_message_type;
  const core_message_type_enum address_message::type                       = core_message_type_enum::address_message_type;
  const core_message_type_enum closing_connection_message::type            = core_message_type_enum::closing_connection_message_type;
  const core_message_type_enum current_time_request_message::type          = core_message_type_enum::current_time_request_message_type;
  const core_message_type_enum current_time_reply_message::type            = core_message_type_enum::current_time_reply_message_type;
  const core_message_type_enum check_firewall_message::type                = core_message_type_enum::check_firewall_message_type;
  const core_message_type_enum check_firewall_reply_message::type          = core_message_type_enum::check_firewall_reply_message_type;

} } // bts::client
<commit_msg>Verify that duplicate enums don't fall out of sync<commit_after>#include <bts/net/core_messages.hpp>

#include <bts/client/messages.hpp>

namespace bts { namespace net {

  const core_message_type_enum item_ids_inventory_message::type            = core_message_type_enum::item_ids_inventory_message_type;
  const core_message_type_enum blockchain_item_ids_inventory_message::type = core_message_type_enum::blockchain_item_ids_inventory_message_type;
  const core_message_type_enum fetch_blockchain_item_ids_message::type     = core_message_type_enum::fetch_blockchain_item_ids_message_type;
  const core_message_type_enum fetch_items_message::type                   = core_message_type_enum::fetch_items_message_type;
  const core_message_type_enum item_not_available_message::type            = core_message_type_enum::item_not_available_message_type;
  const core_message_type_enum hello_message::type                         = core_message_type_enum::hello_message_type;
  const core_message_type_enum connection_accepted_message::type           = core_message_type_enum::connection_accepted_message_type;
  const core_message_type_enum connection_rejected_message::type           = core_message_type_enum::connection_rejected_message_type;
  const core_message_type_enum address_request_message::type               = core_message_type_enum::address_request_message_type;
  const core_message_type_enum address_message::type                       = core_message_type_enum::address_message_type;
  const core_message_type_enum closing_connection_message::type            = core_message_type_enum::closing_connection_message_type;
  const core_message_type_enum current_time_request_message::type          = core_message_type_enum::current_time_request_message_type;
  const core_message_type_enum current_time_reply_message::type            = core_message_type_enum::current_time_reply_message_type;
  const core_message_type_enum check_firewall_message::type                = core_message_type_enum::check_firewall_message_type;
  const core_message_type_enum check_firewall_reply_message::type          = core_message_type_enum::check_firewall_reply_message_type;

} } // bts::client

static_assert(bts::net::block_message_type == bts::client::block_message_type, "enum values don't match");
static_assert(bts::net::trx_message_type == bts::client::trx_message_type, "enum values don't match");<|endoftext|>


<commit_before>// Copyright (c) 2011 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 "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/extensions/user_script_master.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "net/base/mock_host_resolver.h"

using content::WebContents;

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) {
  ASSERT_TRUE(StartTestServer());

  // Loads a simple extension which attempts to change the title of every page
  // that loads to "modified".
  ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito")
      .AppendASCII("content_scripts")));

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  Browser* otr_browser = BrowserList::FindTabbedBrowser(
      browser()->profile()->GetOffTheRecordProfile(), false);
  WebContents* tab = otr_browser->GetSelectedWebContents();

  // Verify the script didn't run.
  bool result = false;
  ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
      tab->GetRenderViewHost(), L"",
      L"window.domAutomationController.send(document.title == 'Unmodified')",
      &result));
  EXPECT_TRUE(result);
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoYesScript) {
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  // Load a dummy extension. This just tests that we don't regress a
  // crash fix when multiple incognito- and non-incognito-enabled extensions
  // are mixed.
  ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts")
      .AppendASCII("all_frames")));

  // Loads a simple extension which attempts to change the title of every page
  // that loads to "modified".
  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("content_scripts")));

  // Dummy extension #2.
  ASSERT_TRUE(LoadExtension(test_data_dir_
      .AppendASCII("content_scripts").AppendASCII("isolated_world1")));

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  Browser* otr_browser = BrowserList::FindTabbedBrowser(
      browser()->profile()->GetOffTheRecordProfile(), false);
  WebContents* tab = otr_browser->GetSelectedWebContents();

  // Verify the script ran.
  bool result = false;
  ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
      tab->GetRenderViewHost(), L"",
      L"window.domAutomationController.send(document.title == 'modified')",
      &result));
  EXPECT_TRUE(result);
}

// Tests that an extension which is enabled for incognito mode doesn't
// accidentially create and incognito profile.
// Test disabled due to http://crbug.com/89054.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_DontCreateIncognitoProfile) {
  ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
  ASSERT_TRUE(RunExtensionTestIncognito(
      "incognito/dont_create_profile")) << message_;
  ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
}

#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) {
#else
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) {
#endif
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  ResultCatcher catcher;

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("apis")));

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}

// Tests that the APIs in an incognito-enabled split-mode extension work
// properly.
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) {
#else
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoSplitMode) {
#endif
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  // We need 2 ResultCatchers because we'll be running the same test in both
  // regular and incognito mode.
  ResultCatcher catcher;
  catcher.RestrictToProfile(browser()->profile());
  ResultCatcher catcher_incognito;
  catcher_incognito.RestrictToProfile(
      browser()->profile()->GetOffTheRecordProfile());

  ExtensionTestMessageListener listener("waiting", true);
  ExtensionTestMessageListener listener_incognito("waiting_incognito", true);

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("split")));

  // Wait for both extensions to be ready before telling them to proceed.
  EXPECT_TRUE(listener.WaitUntilSatisfied());
  EXPECT_TRUE(listener_incognito.WaitUntilSatisfied());
  listener.Reply("go");
  listener_incognito.Reply("go");

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
  EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
}

// Tests that the APIs in an incognito-disabled extension don't see incognito
// events or callbacks.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) {
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  ResultCatcher catcher;

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  ASSERT_TRUE(LoadExtension(test_data_dir_
      .AppendASCII("incognito").AppendASCII("apis_disabled")));

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}

#if defined(OS_WIN)
// http://crbug.com/104438.
#define MAYBE_IncognitoPopup DISABLED_IncognitoPopup
#else
#define MAYBE_IncognitoPopup IncognitoPopup
#endif
// Test that opening a popup from an incognito browser window works properly.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoPopup) {
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  ResultCatcher catcher;

  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("popup")));

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  Browser* incognito_browser = BrowserList::FindTabbedBrowser(
      browser()->profile()->GetOffTheRecordProfile(), false);

  // Simulate the incognito's browser action being clicked.
  BrowserActionTestUtil(incognito_browser).Press(0);

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
<commit_msg>Disable timed out test in Windows<commit_after>// Copyright (c) 2012 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 "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/extensions/user_script_master.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "net/base/mock_host_resolver.h"

using content::WebContents;

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) {
  ASSERT_TRUE(StartTestServer());

  // Loads a simple extension which attempts to change the title of every page
  // that loads to "modified".
  ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito")
      .AppendASCII("content_scripts")));

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  Browser* otr_browser = BrowserList::FindTabbedBrowser(
      browser()->profile()->GetOffTheRecordProfile(), false);
  WebContents* tab = otr_browser->GetSelectedWebContents();

  // Verify the script didn't run.
  bool result = false;
  ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
      tab->GetRenderViewHost(), L"",
      L"window.domAutomationController.send(document.title == 'Unmodified')",
      &result));
  EXPECT_TRUE(result);
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoYesScript) {
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  // Load a dummy extension. This just tests that we don't regress a
  // crash fix when multiple incognito- and non-incognito-enabled extensions
  // are mixed.
  ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts")
      .AppendASCII("all_frames")));

  // Loads a simple extension which attempts to change the title of every page
  // that loads to "modified".
  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("content_scripts")));

  // Dummy extension #2.
  ASSERT_TRUE(LoadExtension(test_data_dir_
      .AppendASCII("content_scripts").AppendASCII("isolated_world1")));

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  Browser* otr_browser = BrowserList::FindTabbedBrowser(
      browser()->profile()->GetOffTheRecordProfile(), false);
  WebContents* tab = otr_browser->GetSelectedWebContents();

  // Verify the script ran.
  bool result = false;
  ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
      tab->GetRenderViewHost(), L"",
      L"window.domAutomationController.send(document.title == 'modified')",
      &result));
  EXPECT_TRUE(result);
}

// Tests that an extension which is enabled for incognito mode doesn't
// accidentially create and incognito profile.
// Test disabled due to http://crbug.com/89054.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_DontCreateIncognitoProfile) {
  ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
  ASSERT_TRUE(RunExtensionTestIncognito(
      "incognito/dont_create_profile")) << message_;
  ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
}

#if defined(OS_WIN)
// http://crbug.com/120484
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) {
#else
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) {
#endif
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  ResultCatcher catcher;

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("apis")));

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}

// Tests that the APIs in an incognito-enabled split-mode extension work
// properly.
#if defined(OS_WIN)
// http://crbug.com/120484
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) {
#else
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoSplitMode) {
#endif
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  // We need 2 ResultCatchers because we'll be running the same test in both
  // regular and incognito mode.
  ResultCatcher catcher;
  catcher.RestrictToProfile(browser()->profile());
  ResultCatcher catcher_incognito;
  catcher_incognito.RestrictToProfile(
      browser()->profile()->GetOffTheRecordProfile());

  ExtensionTestMessageListener listener("waiting", true);
  ExtensionTestMessageListener listener_incognito("waiting_incognito", true);

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("split")));

  // Wait for both extensions to be ready before telling them to proceed.
  EXPECT_TRUE(listener.WaitUntilSatisfied());
  EXPECT_TRUE(listener_incognito.WaitUntilSatisfied());
  listener.Reply("go");
  listener_incognito.Reply("go");

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
  EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
}

// Tests that the APIs in an incognito-disabled extension don't see incognito
// events or callbacks.
#if defined(OS_WIN)
// http://crbug.com/120484
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoDisabled) {
#else
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) {
#endif
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  ResultCatcher catcher;

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  ASSERT_TRUE(LoadExtension(test_data_dir_
      .AppendASCII("incognito").AppendASCII("apis_disabled")));

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}

#if defined(OS_WIN)
// http://crbug.com/104438.
#define MAYBE_IncognitoPopup DISABLED_IncognitoPopup
#else
#define MAYBE_IncognitoPopup IncognitoPopup
#endif
// Test that opening a popup from an incognito browser window works properly.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoPopup) {
  host_resolver()->AddRule("*", "127.0.0.1");
  ASSERT_TRUE(StartTestServer());

  ResultCatcher catcher;

  ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
      .AppendASCII("incognito").AppendASCII("popup")));

  // Open incognito window and navigate to test page.
  ui_test_utils::OpenURLOffTheRecord(
      browser()->profile(),
      test_server()->GetURL("files/extensions/test_file.html"));

  Browser* incognito_browser = BrowserList::FindTabbedBrowser(
      browser()->profile()->GetOffTheRecordProfile(), false);

  // Simulate the incognito's browser action being clicked.
  BrowserActionTestUtil(incognito_browser).Press(0);

  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
<|endoftext|>


<commit_before><?hh //strict

namespace typesafety;

final class Arguments
{

    private ImmVector<string> $argv;

    public function __construct
    (
        Argv $argv
    )
    {
        $this->argv = new ImmVector($argv);
    }

    public function getScriptName() : ScriptName
    {
        return $this->argv->at((int) ArgumentOrder::ScriptName);
    }

    public function getJSONReportFilePath() : Path
    {
        return $this->argv->at((int) ArgumentOrder::JsonReportFilePath);
    }

}
<commit_msg>add fromArray<commit_after><?hh //strict

namespace typesafety;

final class Arguments
{

    private ImmVector<string> $argv;

    public function __construct(
        Argv $argv
    )
    {
        $this->argv = new ImmVector($argv);
    }

    public function getScriptName() : ScriptName
    {
        return $this->argv->at((int) ArgumentOrder::ScriptName);
    }

    public function getJSONReportFilePath() : Path
    {
        return $this->argv->at((int) ArgumentOrder::JsonReportFilePath);
    }

    public static function fromArray(array<string> $argv) : Arguments
    {
        return new Arguments($argv);
    }

}
<|endoftext|>


<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 "chrome/renderer/renderer_main_platform_delegate.h"

#include "base/debug_util.h"

// This is a no op class because we do not have a sandbox on linux.

RendererMainPlatformDelegate::RendererMainPlatformDelegate(
    const MainFunctionParams& parameters)
        : parameters_(parameters) {
}

RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
}

void RendererMainPlatformDelegate::PlatformInitialize() {
}

void RendererMainPlatformDelegate::PlatformUninitialize() {
}

bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
  NOTIMPLEMENTED();
  return true;
}

bool RendererMainPlatformDelegate::EnableSandbox() {
  NOTIMPLEMENTED();
  return true;
}

void RendererMainPlatformDelegate::RunSandboxTests() {
  NOTIMPLEMENTED();
}
<commit_msg>Convert sandbox NOTIMPLEMENTED()s into a bug.<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 "chrome/renderer/renderer_main_platform_delegate.h"

#include "base/debug_util.h"

// This is a no op class because we do not have a sandbox on linux.

RendererMainPlatformDelegate::RendererMainPlatformDelegate(
    const MainFunctionParams& parameters)
        : parameters_(parameters) {
}

RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
}

void RendererMainPlatformDelegate::PlatformInitialize() {
}

void RendererMainPlatformDelegate::PlatformUninitialize() {
}

bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
  // We have no sandbox.
  // http://code.google.com/p/chromium/issues/detail?id=8081
  return true;
}

bool RendererMainPlatformDelegate::EnableSandbox() {
  // We have no sandbox.
  // http://code.google.com/p/chromium/issues/detail?id=8081
  return true;
}

void RendererMainPlatformDelegate::RunSandboxTests() {
  // We have no sandbox.
  // http://code.google.com/p/chromium/issues/detail?id=8081
}
<|endoftext|>