[Scummvm-cvs-logs] CVS: residual primitives.cpp,NONE,1.1 primitives.h,NONE,1.1 Makefile.common,1.18,1.19 driver.h,1.8,1.9 driver_gl.cpp,1.45,1.46 driver_gl.h,1.21,1.22 driver_tinygl.cpp,1.15,1.16 driver_tinygl.h,1.8,1.9 engine.cpp,1.71,1.72 engine.h,1.24,1.25 lua.cpp,1.119,1.120

Pawel Kolodziejski aquadran at users.sourceforge.net
Thu Apr 7 12:29:59 CEST 2005


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4785

Modified Files:
	Makefile.common driver.h driver_gl.cpp driver_gl.h 
	driver_tinygl.cpp driver_tinygl.h engine.cpp engine.h lua.cpp 
Added Files:
	primitives.cpp primitives.h 
Log Message:
added some part of primitives code

--- NEW FILE: primitives.cpp ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  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

#include "debug.h"
#include "font.h"
#include "color.h"
#include "driver.h"
#include "primitives.h"

#include <string>
#include <SDL.h>

PrimitiveObject::PrimitiveObject() {
	_x1 = 0;
	_y1 = 0;
	_x2 = 0;
	_y2 = 0;
	_color._vals[0] = 0;
	_color._vals[1] = 0;
	_color._vals[2] = 0;
	_filled = false;
	_type = 0;
}

PrimitiveObject::~PrimitiveObject() {
}

void PrimitiveObject::createRectangle(int x1, int y1, int x2, int y2, Color color, bool filled) {
	_x1 = x1;
	_y1 = y1;
	_x2 = x2;
	_y2 = y2;
	_color = color;
	_filled = filled;
	_type = 1;
}

void PrimitiveObject::draw() {
	assert(_type);

	if (_type == 1)
		g_driver->drawRectangle(this);
}

--- NEW FILE: primitives.h ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  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 PRIMITIVESOBJECT_H
#define PRIMITIVESOBJECT_H

#include "debug.h"
#include "font.h"
#include "color.h"
#include "driver.h"

#include <string>
#include <SDL.h>

class PrimitiveObject {
public:
	PrimitiveObject();
	~PrimitiveObject();

	void createRectangle(int x1, int y1, int x2, int y2, Color color, bool filled);
	int getX1() { return _x1; }
	int getX2() { return _x2; }
	int getY1() { return _y1; }
	int getY2() { return _y2; }
	Color getColor() { return _color; }
	bool isFilled() { return _filled; }
	void draw();

private:
	int _x1, _x2, _y1, _y2;
	Color _color;
	bool _filled;
	int _type;
};

#endif

Index: Makefile.common
===================================================================
RCS file: /cvsroot/scummvm/residual/Makefile.common,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- Makefile.common	18 Mar 2005 19:54:38 -0000	1.18
+++ Makefile.common	7 Apr 2005 19:29:04 -0000	1.19
@@ -76,6 +76,7 @@
 	matrix4.o \
 	model.o \
 	objectstate.o \
+	primitive.o \
 	registry.o \
 	resource.o \
 	scene.o \

Index: driver.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- driver.h	7 Apr 2005 07:04:36 -0000	1.8
+++ driver.h	7 Apr 2005 19:29:05 -0000	1.9
@@ -25,6 +25,7 @@
 #include "scene.h"
 #include "colormap.h"
 #include "font.h"
+#include "primitives.h"
 
 class Material;
 class Bitmap;
@@ -88,6 +89,8 @@
 	virtual void drawTextBitmap(int x, int y, TextObjectHandle *handle) = 0;
 	virtual void destroyTextBitmap(TextObjectHandle *handle) = 0;
 
+	virtual void drawRectangle(PrimitiveObject *primitive) = 0;
+
 	virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
 	virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
 

Index: driver_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.cpp,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- driver_gl.cpp	7 Apr 2005 07:04:36 -0000	1.45
+++ driver_gl.cpp	7 Apr 2005 19:29:05 -0000	1.46
@@ -686,3 +686,43 @@
 
 void DriverGL::drawDim() {
 }
+
+void DriverGL::drawRectangle(PrimitiveObject *primitive) {
+	int x1 = primitive->getX1();
+	int x2 = primitive->getX2();
+	int y1 = primitive->getY1();
+	int y2 = primitive->getY2();
+
+	Color color = primitive->getColor();
+	uint32 c = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8) | 255;
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(0, 640, 480, 0, 0, 1);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+	glDisable(GL_LIGHTING);
+	glEnable(GL_TEXTURE_2D);
+	glDisable(GL_DEPTH_TEST);
+	glDepthMask(GL_FALSE);
+
+	if (primitive->isFilled()) {
+		glBegin(GL_QUADS);
+	} else {
+		glBegin(GL_LINES);
+	}
+	
+	glColor3i(color.red(), color.green(), color.blue());
+
+	glVertex2i(x1, 480 - y1);
+	glVertex2i(x2, 480 - y1);
+	glVertex2i(x2, 480 - y2);
+	glVertex2i(x1, 480 - y2);
+	glEnd();
+
+	glDisable(GL_TEXTURE_2D);
+	glDisable(GL_BLEND);
+	glDepthMask(GL_TRUE);
+	glEnable(GL_DEPTH_TEST);
+	glEnable(GL_LIGHTING);
+}

Index: driver_gl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- driver_gl.h	7 Apr 2005 07:04:36 -0000	1.21
+++ driver_gl.h	7 Apr 2005 19:29:05 -0000	1.22
@@ -73,6 +73,8 @@
 	void drawTextBitmap(int x, int y, TextObjectHandle *handle);
 	void destroyTextBitmap(TextObjectHandle *handle);
 
+	void drawRectangle(PrimitiveObject *primitive);
+
 	void prepareSmushFrame(int width, int height, byte *bitmap);
 	void drawSmushFrame(int offsetX, int offsetY);
 

Index: driver_tinygl.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_tinygl.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- driver_tinygl.cpp	7 Apr 2005 07:04:36 -0000	1.15
+++ driver_tinygl.cpp	7 Apr 2005 19:29:05 -0000	1.16
@@ -124,14 +124,14 @@
 }
 
 void DriverTinyGL::toggleFullscreenMode() {
-	Uint32 flags = SDL_HWSURFACE;
+	uint32 flags = SDL_HWSURFACE;
 
-	if (! _isFullscreen)
+	if (!_isFullscreen)
 		flags |= SDL_FULLSCREEN;
 	if (SDL_SetVideoMode(_screenWidth, _screenHeight, _screenBPP, flags) == 0)
 		warning("Could not change fullscreen mode");
 	else
-		_isFullscreen = ! _isFullscreen;
+		_isFullscreen = !_isFullscreen;
 }
 
 void DriverTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) {
@@ -474,3 +474,35 @@
 
 void DriverTinyGL::drawDim() {
 }
+
+void DriverTinyGL::drawRectangle(PrimitiveObject *primitive) {
+	uint16 *dst = (uint16 *)_screen->pixels;
+	int x1 = primitive->getX1();
+	int x2 = primitive->getX2();
+	int y1 = primitive->getY1();
+	int y2 = primitive->getY2();
+
+	Color color = primitive->getColor();
+	uint16 c = ((color.red() & 0xF8) << 8) | ((color.green() & 0xFC) << 3) | (color.blue() >> 3);
+
+	if (primitive->isFilled()) {
+		for (; y1 < y2; y1++) {
+			for (int x = x1; x < x2; x++) {
+				WRITE_LE_UINT16(dst + 640 * y1 + x, c);
+			}
+		}
+	} else {
+		for (int x = x1; x < x2; x++) {
+			WRITE_LE_UINT16(dst + 640 * y1 + x, c);
+		}
+		for (int x = x1; x < x2; x++) {
+			WRITE_LE_UINT16(dst + 640 * y2 + x, c);
+		}
+		for (int y = y1; y1 < y2; y++) {
+			WRITE_LE_UINT16(dst + 640 * y + x1, c);
+		}
+		for (int y = y1; y1 < y2; y++) {
+			WRITE_LE_UINT16(dst + 640 * y + x2, c);
+		}
+	}
+}

Index: driver_tinygl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_tinygl.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- driver_tinygl.h	7 Apr 2005 07:04:36 -0000	1.8
+++ driver_tinygl.h	7 Apr 2005 19:29:05 -0000	1.9
@@ -75,6 +75,8 @@
 	void drawTextBitmap(int x, int y, TextObjectHandle *handle);
 	void destroyTextBitmap(TextObjectHandle *handle);
 
+	void drawRectangle(PrimitiveObject *primitive);
+
 	void prepareSmushFrame(int width, int height, byte *bitmap);
 	void drawSmushFrame(int offsetX, int offsetY);
 

Index: engine.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/engine.cpp,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- engine.cpp	5 Apr 2005 13:50:47 -0000	1.71
+++ engine.cpp	7 Apr 2005 19:29:05 -0000	1.72
@@ -230,6 +230,11 @@
 			}
 		}
 
+		// Draw Primitives
+		for (PrimitiveListType::iterator i = _primitiveObjects.begin(); i != _primitiveObjects.end(); i++) {
+			(*i)->draw();
+		}
+
 		// Draw text
 		for (TextListType::iterator i = _textObjects.begin(); i != _textObjects.end(); i++) {
 			(*i)->draw();

Index: engine.h
===================================================================
RCS file: /cvsroot/scummvm/residual/engine.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- engine.h	5 Apr 2005 13:50:53 -0000	1.24
+++ engine.h	7 Apr 2005 19:29:05 -0000	1.25
@@ -21,6 +21,7 @@
 #include "bits.h"
 #include "scene.h"
 #include "textobject.h"
+#include "primitives.h"
 #include "font.h"
 #include "lua.h"
 
@@ -87,7 +88,7 @@
 	SDLK_AXIS_MOUSE_Y,
 	SDLK_AXIS_MOUSE_Z,
 	SDLK_EXTRA_LAST
-	};
+};
 
 class Engine {
 public:
@@ -144,6 +145,26 @@
 		}
 	}
 
+	// Primitives Object Registration
+	typedef std::list<PrimitiveObject *> PrimitiveListType;
+	PrimitiveListType::const_iterator primitivesBegin() const {
+		return _primitiveObjects.begin();
+	}
+	PrimitiveListType::const_iterator primitivesEnd() const {
+		return _primitiveObjects.end();
+	}
+
+	void registerPrimitiveObject(PrimitiveObject *a) { _primitiveObjects.push_back(a); }
+	void killPrimitiveObject(PrimitiveObject *a) {
+		_primitiveObjects.remove(a);
+	}
+	void killPrimitiveObjects() {
+		while (!_primitiveObjects.empty()) {
+			delete _primitiveObjects.back();
+			_primitiveObjects.pop_back();
+		}
+	}
+
 	void savegameSave();
 	void savegameRestore();
 	static void savegameGzread(void *data, int size);
@@ -173,6 +194,7 @@
 	ActorListType _actors;
 	Actor *_selectedActor;
 	TextListType _textObjects;
+	PrimitiveListType _primitiveObjects;
 };
 
 extern Engine *g_engine;

Index: lua.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua.cpp,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -d -r1.119 -r1.120
--- lua.cpp	7 Apr 2005 07:04:36 -0000	1.119
+++ lua.cpp	7 Apr 2005 19:29:05 -0000	1.120
@@ -1563,7 +1563,7 @@
 		lua_pushobject(tableObj);
 		lua_pushstring("filled");
 		lua_Object objFilled = lua_gettable();
-		if (!lua_isnil(objFilled)) 
+		if (!lua_isnil(objFilled))
 			filled = true;
 	}
 





More information about the Scummvm-git-logs mailing list