source: golgotha/src/i4/time/win32_timedev.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.8 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include <windows.h>
10#include <windowsx.h>
11
12
13#include "arch.hh"
14#include "time/time.hh"
15#include "time/timedev.hh"
16#include "device/kernel.hh"
17#include "init/init.hh"
18
19i4_time_device_class i4_time_dev;
20
21class i4_time_device_adder_class : public i4_init_class
22{
23  public :
24  void init()
25  {
26    i4_kernel.add_device(&i4_time_dev);
27  }
28} i4_time_device_adder_instance;
29
30
31
32i4_bool i4_time_device_class::cancel_event(const id &handle)
33{
34  i4_isl_list<timed_event>::iterator i=events.begin(),last=events.end();
35  for (;i!=events.end();++i)
36  {
37    if (handle.reference==&*i)
38    {
39      if (last==events.end())
40        events.erase();
41      else
42        events.erase_after(last);
43      timeKillEvent(i->win32_timer_id);
44      delete &*i;
45      return i4_T;
46    }
47    last=i;
48  }
49  return i4_F;
50}
51
52i4_bool i4_time_device_class::process_events()       // returns true if an event was dispatched
53{
54  return i4_F;
55}
56
57void CALLBACK win32_timer_callback(UINT id, UINT msg, DWORD user, DWORD dw1, DWORD dw2)
58{
59  i4_time_dev.callback(user);
60}
61
62void i4_time_device_class::callback(w32 user)
63{
64  timed_event *got_event=(timed_event *)(user);
65  got_event->send_to->receive_event(got_event->event);
66
67  if (got_event==&*i4_time_dev.events.begin())
68    events.erase();
69  else
70  {
71    i4_isl_list<timed_event>::iterator i=events.begin(),last=events.end();
72    for (; i->next!=got_event && i!=last; ++i);
73
74    if (i!=last)
75      events.erase_after(i);   
76  }
77  delete got_event;
78}
79
80// who to send the event to
81i4_time_device_class::id i4_time_device_class::request_event(i4_event_handler_class *send_to,
82                                       i4_event *event,                 // what event to send
83                                       w32 milli_wait) // how much time to wait (in milli-seconds)
84{
85  // first make sure this is not an event that needs to be sent right now
86  // these events usually are two-way events that have return codes inside
87  if (event->when()==i4_event::NOW)
88    i4_error("Cannot send NOW events throught the time device!");
89 
90  timed_event *ev=new timed_event(send_to,event,milli_wait);
91  events.insert(*ev);
92  ev->win32_timer_id=timeSetEvent(milli_wait,0,
93                                  win32_timer_callback,
94                                  (DWORD)(ev),
95                                  TIME_ONESHOT);
96
97  return id(ev);
98}
Note: See TracBrowser for help on using the repository browser.