~ubuntu-branches/ubuntu/vivid/rlvm/vivid

« back to all changes in this revision

Viewing changes to src/effects/effect.cc

  • Committer: Package Import Robot
  • Author(s): Ying-Chun Liu (PaulLiu)
  • Date: 2014-10-22 03:24:19 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20141022032419-yqxls9ky4n1w811n
Tags: 0.14-1
* New upstream release
* Bump Standards-Version to 3.9.6: nothing needs to be changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi:tw=80:et:ts=2:sts=2
 
3
//
 
4
// -----------------------------------------------------------------------
 
5
//
 
6
// This file is part of RLVM, a RealLive virtual machine clone.
 
7
//
 
8
// -----------------------------------------------------------------------
 
9
//
 
10
// Copyright (C) 2006 Elliot Glaysher
 
11
//
 
12
// This program is free software; you can redistribute it and/or modify
 
13
// it under the terms of the GNU General Public License as published by
 
14
// the Free Software Foundation; either version 3 of the License, or
 
15
// (at your option) any later version.
 
16
//
 
17
// This program is distributed in the hope that it will be useful,
 
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
// GNU General Public License for more details.
 
21
//
 
22
// You should have received a copy of the GNU General Public License
 
23
// along with this program; if not, write to the Free Software
 
24
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
25
//
 
26
// -----------------------------------------------------------------------
 
27
 
 
28
#include "effects/effect.h"
 
29
 
 
30
#include "machine/rlmachine.h"
 
31
#include "systems/base/event_system.h"
 
32
#include "systems/base/graphics_system.h"
 
33
#include "systems/base/surface.h"
 
34
#include "systems/base/system.h"
 
35
 
 
36
// -----------------------------------------------------------------------
 
37
// Effect
 
38
// -----------------------------------------------------------------------
 
39
 
 
40
Effect::Effect(RLMachine& machine,
 
41
               std::shared_ptr<Surface> src,
 
42
               std::shared_ptr<Surface> dst,
 
43
               Size size,
 
44
               int time)
 
45
    : screen_size_(size),
 
46
      duration_(time),
 
47
      start_time_(machine.system().event().GetTicks()),
 
48
      machine_(machine),
 
49
      src_surface_(src),
 
50
      dst_surface_(dst) {
 
51
  machine.system().graphics().set_is_responsible_for_update(false);
 
52
}
 
53
 
 
54
Effect::~Effect() {
 
55
  machine_.system().graphics().set_is_responsible_for_update(true);
 
56
}
 
57
 
 
58
bool Effect::operator()(RLMachine& machine) {
 
59
  unsigned int time = machine.system().event().GetTicks();
 
60
  unsigned int current_frame = time - start_time_;
 
61
 
 
62
  bool fast_forward = machine.system().ShouldFastForward();
 
63
 
 
64
  if (current_frame >= duration_ || fast_forward) {
 
65
    return true;
 
66
  } else {
 
67
    GraphicsSystem& graphics = machine.system().graphics();
 
68
    graphics.BeginFrame();
 
69
 
 
70
    if (BlitOriginalImage()) {
 
71
      dst_surface().RenderToScreen(
 
72
          Rect(Point(0, 0), size()), Rect(Point(0, 0), size()), 255);
 
73
    }
 
74
 
 
75
    PerformEffectForTime(machine, current_frame);
 
76
 
 
77
    graphics.EndFrame();
 
78
    return false;
 
79
  }
 
80
}
 
81
 
 
82
// -----------------------------------------------------------------------
 
83
// BlitAfterEffectFinishes
 
84
// -----------------------------------------------------------------------
 
85
 
 
86
BlitAfterEffectFinishes::BlitAfterEffectFinishes(LongOperation* in,
 
87
                                                 std::shared_ptr<Surface> src,
 
88
                                                 std::shared_ptr<Surface> dst,
 
89
                                                 const Rect& srcRect,
 
90
                                                 const Rect& destRect)
 
91
    : PerformAfterLongOperationDecorator(in),
 
92
      src_surface_(src),
 
93
      dst_surface_(dst),
 
94
      src_rect_(srcRect),
 
95
      dest_rect_(destRect) {}
 
96
 
 
97
BlitAfterEffectFinishes::~BlitAfterEffectFinishes() {}
 
98
 
 
99
void BlitAfterEffectFinishes::PerformAfterLongOperation(RLMachine& machine) {
 
100
  // Blit DC1 onto DC0, with full opacity, and end the operation
 
101
  src_surface_->BlitToSurface(*dst_surface_, src_rect_, dest_rect_, 255);
 
102
 
 
103
  // Now force a screen refresh
 
104
  machine.system().graphics().ForceRefresh();
 
105
}