[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Feuerkraft-CVS] rev 320 - in trunk/src: . input
From: |
Ingo Ruhnke |
Subject: |
[Feuerkraft-CVS] rev 320 - in trunk/src: . input |
Date: |
Wed, 10 Dec 2003 13:11:31 +0100 |
Author: grumbel
Date: 2003-12-10 13:11:31 +0100 (Wed, 10 Dec 2003)
New Revision: 320
Added:
trunk/src/input/input_manager_player.cxx
trunk/src/input/input_manager_player.hxx
trunk/src/input/input_recorder.cxx
trunk/src/input/input_recorder.hxx
trunk/src/screenshot.cxx
trunk/src/screenshot.hxx
Modified:
trunk/src/Makefile.am
trunk/src/game_session.cxx
trunk/src/input/Makefile.am
trunk/src/input/input_manager.cxx
trunk/src/input/input_manager.hxx
Log:
- added screenshot support
- added input recording support
- added playback of recorded event support
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/Makefile.am 2003-12-10 12:11:31 UTC (rev 320)
@@ -127,6 +127,8 @@
satchel_charge.cxx \
screen.cxx \
screen.hxx \
+screenshot.hxx \
+screenshot.cxx \
scm_functor.hxx \
scm_functor.cxx \
scm_sequence_hook.hxx \
Modified: trunk/src/game_session.cxx
===================================================================
--- trunk/src/game_session.cxx 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/game_session.cxx 2003-12-10 12:11:31 UTC (rev 320)
@@ -57,6 +57,8 @@
#include "player.hxx"
#include "path_manager.hxx"
#include "command_line_arguments.hxx"
+#include "string_converter.hxx"
+#include "screenshot.hxx"
#include "game_session.hxx"
// FIXME: Replace this with a PlayerManager class or something similar
@@ -231,6 +233,7 @@
// Flip front and backbuffer. This makes the changes visible:
CL_Display::flip ();
+ Screenshot::write_screenshot_pnm("/tmp/feuerkraft/" + to_string(frames));
++frames;
// Update keyboard input and handle system events:
Modified: trunk/src/input/Makefile.am
===================================================================
--- trunk/src/input/Makefile.am 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/input/Makefile.am 2003-12-10 12:11:31 UTC (rev 320)
@@ -10,6 +10,8 @@
input_manager_impl.cxx \
input_manager_custom.hxx \
input_manager_custom.cxx \
+ input_manager_player.hxx \
+ input_manager_player.cxx \
input_button.hxx \
input_axis.hxx \
input_button_input_device.hxx \
@@ -21,6 +23,8 @@
button_factory.hxx \
button_factory.cxx \
axis_factory.hxx \
- axis_factory.cxx
+ axis_factory.cxx \
+ input_recorder.hxx \
+ input_recorder.cxx
# EOF #
Modified: trunk/src/input/input_manager.cxx
===================================================================
--- trunk/src/input/input_manager.cxx 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/input/input_manager.cxx 2003-12-10 12:11:31 UTC (rev 320)
@@ -24,11 +24,14 @@
#include <ClanLib/Display/joystick.h>
#include "../command_line_arguments.hxx"
#include "input_manager_custom.hxx"
+#include "input_manager_player.hxx"
#include "input_manager_impl.hxx"
+#include "input_recorder.hxx"
#include "input_manager.hxx"
extern CommandLineArguments* args;
InputManagerImpl* InputManager::impl = 0;
+InputRecorder* InputManager::recorder = 0;
void
InputManager::init(InputManagerImpl* arg_impl)
@@ -39,6 +42,17 @@
impl = 0;
}
+ if (recorder)
+ {
+ delete recorder;
+ recorder = 0;
+ }
+
+ if (!recorder)
+ {
+ recorder = new InputRecorder("/tmp/feuerkraft.rec");
+ }
+
if (arg_impl)
{
impl = arg_impl;
@@ -69,6 +83,9 @@
if (!impl)
{
+#if 1
+ impl = new InputManagerPlayer("/tmp/feuerkraft1.rec");
+#else
// Set default configuration
impl = new InputManagerCustom
(gh_eval_str("'("
@@ -80,30 +97,9 @@
"(accelerate-axis (joystick-axis 1 1))"
"(strafe-axis (joystick-axis 1 2))"
")"));
+#endif
}
}
- /*
- else if (args->joystick != -1)
- {
- if (args->joystick < CL_Joystick::get_device_count())
- {
- std::cout << "InputManager: Using joystick " << args->joystick <<
std::endl;
- impl = new InputManagerJoystick();
- }
- else
- {
- std::ostringstream os;
- os << "Feuerkraft: ClanLib doesn't have joystick number " << args->joystick
- << ", only " << CL_Joystick::get_device_count() << " joysticks available"
<< std::endl;
- throw std::runtime_error(os.str());
- }
- }
- else
- {
- std::cout << "InputManager: Using keyboard" << std::endl;
- impl = new InputManagerKeyboard();
- }
- */
}
void
@@ -117,6 +113,7 @@
{
assert(impl);
impl->update(delta);
+ recorder->record(get_controller());
}
InputEventLst
Modified: trunk/src/input/input_manager.hxx
===================================================================
--- trunk/src/input/input_manager.hxx 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/input/input_manager.hxx 2003-12-10 12:11:31 UTC (rev 320)
@@ -24,6 +24,7 @@
#include "controller.hxx"
#include "input_event.hxx"
+class InputRecorder;
class InputManagerImpl;
/** */
@@ -31,6 +32,7 @@
{
private:
static InputManagerImpl* impl;
+ static InputRecorder* recorder;
public:
static void init(InputManagerImpl* arg_impl = 0);
static void deinit();
Added: trunk/src/input/input_manager_player.cxx
===================================================================
--- trunk/src/input/input_manager_player.cxx 2003-12-09 22:52:19 UTC (rev
319)
+++ trunk/src/input/input_manager_player.cxx 2003-12-10 12:11:31 UTC (rev
320)
@@ -0,0 +1,98 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include <iostream>
+#include "input_manager_player.hxx"
+
+InputManagerPlayer::InputManagerPlayer(const std::string& filename)
+{
+ std::cout << "InputManagerPlayer::InputManagerPlayer(" << filename << ")" <<
std::endl;
+ entry_counter = 0;
+ SCM port = scm_open_file(gh_str02scm(filename.c_str()),
+ gh_str02scm("r"));
+ SCM entry;
+ while(scm_eof_object_p(entry = scm_read(port)) == SCM_BOOL_F)
+ {
+ InputEventLst lst;
+ int entry_num = gh_scm2int(gh_cadr(entry));
+ entry = gh_cddr(entry);
+
+ while(gh_pair_p(entry))
+ {
+ lst.push_back(scm2event(gh_car(entry)));
+ entry = gh_cdr(entry);
+ }
+
+ std::cout << "Entry: " << entry_num << " events: " << lst.size() <<
std::endl;
+ entries.push(Entry(entry_num, lst));
+ }
+ gh_display(entry);gh_newline();
+ scm_close_port(port);
+}
+
+InputEvent
+InputManagerPlayer::scm2event(SCM entry)
+{
+ InputEvent event;
+ SCM sym = gh_car(entry);
+ SCM data = gh_cdr(entry);
+
+ if (gh_equal_p(gh_symbol2scm("axis"), sym))
+ {
+ event.type = AXIS_EVENT;
+ event.axis.name = (AxisName)gh_scm2int(gh_car(data));
+ event.axis.pos = gh_scm2double(gh_cadr(data));
+ }
+ else if (gh_equal_p(gh_symbol2scm("button"), sym))
+ {
+ event.type = BUTTON_EVENT;
+ event.button.name = (ButtonName)gh_scm2int(gh_car(data));
+ event.button.down = gh_scm2int(gh_cadr(data));
+ }
+ else
+ {
+ std::cout << "scm2event: Unknown sym: ";
+ gh_display(sym);
+ std::cout << std::endl;
+ }
+ return event;
+}
+
+void
+InputManagerPlayer::update(float delta)
+{
+ std::cout << "Got: " << entry_counter << " " << entries.front().entry_num <<
std::endl;
+ if (entries.front().entry_num == entry_counter)
+ {
+ events = entries.front().events;
+
+ for (InputEventLst::iterator i = events.begin(); i != events.end(); ++i)
+ {
+ if (i->type == AXIS_EVENT)
+ controller.set_axis_state(i->axis.name, i->axis.pos);
+ else if (i->type == BUTTON_EVENT)
+ controller.set_button_state(i->button.name, i->button.down);
+ }
+ entries.pop();
+ }
+
+ entry_counter += 1;
+}
+
+/* EOF */
Added: trunk/src/input/input_manager_player.hxx
===================================================================
--- trunk/src/input/input_manager_player.hxx 2003-12-09 22:52:19 UTC (rev
319)
+++ trunk/src/input/input_manager_player.hxx 2003-12-10 12:11:31 UTC (rev
320)
@@ -0,0 +1,55 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef HEADER_INPUT_MANAGER_PLAYER_HXX
+#define HEADER_INPUT_MANAGER_PLAYER_HXX
+
+#include <queue>
+#include <string>
+#include <guile/gh.h>
+#include "input_manager_impl.hxx"
+
+/** Playback class for events recorded my the InputRecorder */
+class InputManagerPlayer : public InputManagerImpl
+{
+private:
+ struct Entry {
+ Entry(int num, const InputEventLst& lst)
+ : entry_num(num), events(lst)
+ {}
+ int entry_num;
+ InputEventLst events;
+ };
+
+ int entry_counter;
+ std::queue<Entry> entries;
+public:
+ InputManagerPlayer(const std::string& filename);
+
+ void update(float delta);
+private:
+ InputEvent scm2event(SCM lst);
+
+ InputManagerPlayer (const InputManagerPlayer&);
+ InputManagerPlayer& operator= (const InputManagerPlayer&);
+};
+
+#endif
+
+/* EOF */
Added: trunk/src/input/input_recorder.cxx
===================================================================
--- trunk/src/input/input_recorder.cxx 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/input/input_recorder.cxx 2003-12-10 12:11:31 UTC (rev 320)
@@ -0,0 +1,61 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include "input_recorder.hxx"
+
+InputRecorder::InputRecorder(const std::string& filename)
+ : out(filename.c_str())
+{
+ entry_counter = 0;
+}
+
+InputRecorder::~InputRecorder()
+{
+ out.close();
+}
+
+void
+InputRecorder::record(const Controller& controller)
+{
+ InputEventLst lst = controller.get_events();
+
+ if (!lst.empty())
+ {
+ out << "(entry " << entry_counter << std::endl;
+
+ for (InputEventLst::iterator i = lst.begin(); i != lst.end(); ++i)
+ {
+ switch(i->type)
+ {
+ case AXIS_EVENT:
+ out << " (axis " << i->axis.name << " " << i->axis.get_pos() <<
")" << std::endl;
+ break;
+
+ case BUTTON_EVENT:
+ out << " (button " << i->button.name << " " << i->button.down
<< ")" << std::endl;
+ break;
+ }
+ }
+ out << ")\n" << std::endl;
+ }
+
+ entry_counter += 1;
+}
+
+/* EOF */
Added: trunk/src/input/input_recorder.hxx
===================================================================
--- trunk/src/input/input_recorder.hxx 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/input/input_recorder.hxx 2003-12-10 12:11:31 UTC (rev 320)
@@ -0,0 +1,46 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef HEADER_INPUT_RECORDER_HXX
+#define HEADER_INPUT_RECORDER_HXX
+
+#include <fstream>
+#include "controller.hxx"
+
+/** The InputRecorder hooks into the InputManager and records all
+ input events to a file, thus allowing the later playback of the
+ events. */
+class InputRecorder
+{
+private:
+ std::ofstream out;
+ int entry_counter;
+public:
+ InputRecorder(const std::string& filename);
+ ~InputRecorder();
+
+ void record(const Controller& controller);
+private:
+ InputRecorder (const InputRecorder&);
+ InputRecorder& operator= (const InputRecorder&);
+};
+
+#endif
+
+/* EOF */
Added: trunk/src/screenshot.cxx
===================================================================
--- trunk/src/screenshot.cxx 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/screenshot.cxx 2003-12-10 12:11:31 UTC (rev 320)
@@ -0,0 +1,86 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include <stdio.h>
+#include <iostream>
+#include <ClanLib/Display/display.h>
+#include <ClanLib/Display/display_window.h>
+#include <ClanLib/Display/pixel_buffer.h>
+#include <ClanLib/Display/pixel_format.h>
+#include "screenshot.hxx"
+
+void
+Screenshot::write_screenshot_pnm(const std::string& filename)
+{
+ CL_PixelBuffer* buf = take_screen_shot();
+
+ FILE* out = fopen(filename.c_str(), "wb");
+
+ if (!out)
+ {
+ perror(filename.c_str());
+ std::cout << "Screenshot: Couldn't write file: " << filename <<
std::endl;
+ return;
+ }
+
+ buf->lock();
+ int width = buf->get_width();
+ int pitch = buf->get_width()*3;
+ int height = buf->get_height();
+
+ fprintf(out,
+ "P6\n"
+ "# CREATOR: Feuerkraft\n"
+ "%d %d\n"
+ "255\n",
+ width,
+ height);
+
+ unsigned char* data = static_cast<unsigned char*>(buf->get_data());
+
+ for(int i = height-1; i >= 0; --i)
+ {
+ fwrite(data + pitch*i,
+ sizeof(unsigned char),
+ pitch,
+ out);
+ }
+
+ buf->unlock();
+ fclose(out);
+
+ delete buf;
+}
+
+CL_PixelBuffer*
+Screenshot::take_screen_shot()
+{
+ CL_PixelBuffer back_buffer =
CL_Display::get_current_window()->get_back_buffer();
+
+ unsigned short width = back_buffer.get_width();
+ unsigned short height = back_buffer.get_height();
+
+ CL_PixelBuffer *pbuf = new CL_PixelBuffer(width, height, width*3,
CL_PixelFormat::bgr888);
+ back_buffer.convert(pbuf);
+
+ return pbuf;
+}
+
+
+/* EOF */
Added: trunk/src/screenshot.hxx
===================================================================
--- trunk/src/screenshot.hxx 2003-12-09 22:52:19 UTC (rev 319)
+++ trunk/src/screenshot.hxx 2003-12-10 12:11:31 UTC (rev 320)
@@ -0,0 +1,41 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef HEADER_SCREENSHOT_HXX
+#define HEADER_SCREENSHOT_HXX
+
+#include <string>
+
+class CL_PixelBuffer;
+
+/** */
+class Screenshot
+{
+private:
+public:
+ static CL_PixelBuffer* take_screen_shot();
+ static void write_screenshot_pnm(const std::string& filename);
+private:
+ Screenshot (const Screenshot&);
+ Screenshot& operator= (const Screenshot&);
+};
+
+#endif
+
+/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Feuerkraft-CVS] rev 320 - in trunk/src: . input,
Ingo Ruhnke <=