Move walkplane/sector code to seperate file

This commit is contained in:
James Brown 2003-08-19 07:20:03 +00:00
parent 452c22287a
commit 0e355abcaf
6 changed files with 134 additions and 70 deletions

View File

@ -5,7 +5,8 @@ LIBS = -lSDL -lGL -lGLU -Llua/lib -llua -llualib `sdl-config --libs`
OBJS = main.o lab.o bitmap.o model.o resource.o material.o debug.o \
textsplit.o lua.o registry.o localize.o scene.o engine.o actor.o \
sound.o mixer.o keyframe.o costume.o
sound.o mixer.o keyframe.o costume.o walkplane.o
DEPS = $(OBJS:.o=.d)
residual: $(OBJS) lua/lib/liblua.a lua/lib/liblualib.a

13
lua.cpp
View File

@ -462,13 +462,14 @@ static void IsActorInSector(void) {
warning("IsActorInSector(%s, %s): SEMI-STUB", act->name(), name);
for (i=0; i<numSectors; i++) {
const char *sector_name = Engine::instance()->currScene()->getSectorName(i);
if (sector_name && strstr(sector_name, name)) {
Sector *sector = Engine::instance()->currScene()->getSectorBase(i);
if (strstr(sector->name(), name)) {
warning("found sector!");
if (Engine::instance()->currScene()->isPointInSector(i, act->pos())) {
lua_pushnumber(Engine::instance()->currScene()->getSectorID(i));
lua_pushstring((char*)Engine::instance()->currScene()->getSectorName(i));
lua_pushnumber(Engine::instance()->currScene()->getSectorType(i));
if (sector->isPointInSector(act->pos())) {
lua_pushnumber(sector->id());
lua_pushstring((char*)sector->name());
lua_pushnumber(sector->type());
}
}
}

View File

@ -84,52 +84,6 @@ Scene::~Scene() {
delete [] sectors_;
}
void Scene::Sector::load(TextSplitter &ts) {
char buf[256];
int id = 0;
ts.scanString(" sector %256s", 1, buf);
ts.scanString(" id %d", 1, &id);
load0(ts, buf, id);
}
void Scene::Sector::load0(TextSplitter &ts, char *name, int id) {
char buf[256];
int i = 0;
float height = 12345.f; // Yaz: this is in the original code...
Vector3d tempVert;
name_ = name;
id_ = id;
ts.scanString(" type %256s", 1, buf);
// FIXME: I don't think these are right (see grim loc_4A7D19, result is var_200?)
// Yaz: actualy, those should be flags that are later used function at 4A66C0 (I named it buildWalkPlane)
if (strstr(buf, "walk"))
type_ = 0x1000;
else if (strstr(buf, "funnel"))
type_ = 0x1100;
else if (strstr(buf, "camera"))
type_ = 0x2000;
else if (strstr(buf, "special"))
type_ = 0x4000;
else if (strstr(buf, "chernobyl"))
type_ = 0x8000;
else
error("Unknown sector type '%s' in room setup", buf);
ts.scanString(" default visibility %256s", 1, buf);
visibility_ = buf;
ts.scanString(" height %f", 1, &height_);
ts.scanString(" numvertices %d", 1, &numVertices_);
vertices_ = new Vector3d[numVertices_];
ts.scanString(" vertices: %f %f %f", 3, &vertices_[0].x(), &vertices_[0].y(), &vertices_[0].z());
for (i=1;i<numVertices_;i++)
ts.scanString(" %f %f %f", 3, &vertices_[i].x(), &vertices_[i].y(), &vertices_[i].z());
}
void Scene::Setup::load(TextSplitter &ts) {
char buf[256];

23
scene.h
View File

@ -22,6 +22,7 @@
#include "bitmap.h"
#include "color.h"
#include "debug.h"
#include "walkplane.h"
#include <SDL.h>
#include <SDL_opengl.h>
#include <string>
@ -56,14 +57,13 @@ public:
int setup() const { return currSetup_ - setups_; }
// Sector access functions
#define validSector(id) ((numSectors_ >= 0) && (id < numSectors_))
int getSectorCount() { return numSectors_; }
const char *getSectorName(int id) const {
if (validSector(id)) return sectors_[id].name_.c_str(); else return NULL;
Sector *getSectorBase(int id) {
if ((numSectors_ >= 0) && (id < numSectors_))
return &sectors_[id];
else
return NULL;
}
int getSectorType(int id) { if (validSector(id)) return sectors_[id].type_; else return -1; }
int getSectorID(int id) { if (validSector(id)) return sectors_[id].id_; else return -1; }
bool isPointInSector(int id, Vector3d point) { return false; } // FIXME: Need pointInPoly func
private:
struct Setup { // Camera setup data
@ -84,17 +84,6 @@ private:
float intensity_, umbraangle_, penumbraangle_;
};
struct Sector { // Walkarea 'sectors'
void load(TextSplitter &ts);
void load0(TextSplitter &ts, char *name, int id);
int numVertices_, id_;
std::string name_;
int type_;
std::string visibility_;
Vector3d *vertices_;
float height_;
};
std::string name_;
int numCmaps_;
ResPtr<Colormap> *cmaps_;

68
walkplane.cpp Normal file
View File

@ -0,0 +1,68 @@
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003 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 "walkplane.h"
#include "textsplit.h"
void Sector::load(TextSplitter &ts) {
char buf[256];
int id = 0;
ts.scanString(" sector %256s", 1, buf);
ts.scanString(" id %d", 1, &id);
load0(ts, buf, id);
}
void Sector::load0(TextSplitter &ts, char *name, int id) {
char buf[256];
int i = 0;
float height = 12345.f; // Yaz: this is in the original code...
Vector3d tempVert;
name_ = name;
id_ = id;
ts.scanString(" type %256s", 1, buf);
// Flags used in function at 4A66C0 (buildWalkPlane)
if (strstr(buf, "walk"))
type_ = 0x1000;
else if (strstr(buf, "funnel"))
type_ = 0x1100;
else if (strstr(buf, "camera"))
type_ = 0x2000;
else if (strstr(buf, "special"))
type_ = 0x4000;
else if (strstr(buf, "chernobyl"))
type_ = 0x8000;
else
error("Unknown sector type '%s' in room setup", buf);
ts.scanString(" default visibility %256s", 1, buf);
visibility_ = buf;
ts.scanString(" height %f", 1, &height_);
ts.scanString(" numvertices %d", 1, &numVertices_);
vertices_ = new Vector3d[numVertices_];
ts.scanString(" vertices: %f %f %f", 3, &vertices_[0].x(), &vertices_[0].y(),
&vertices_[0].z());
for (i=1;i<numVertices_;i++)
ts.scanString(" %f %f %f", 3, &vertices_[i].x(), &vertices_[i].y(), &vertices_[i].z());
}

51
walkplane.h Normal file
View File

@ -0,0 +1,51 @@
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003 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 WALKPLANE_H
#define WALKPLANE_H
#include "vector3d.h"
#include "debug.h"
#include <SDL.h>
#include <SDL_opengl.h>
#include <string>
class TextSplitter;
class Sector {
public:
void load(TextSplitter &ts);
void load0(TextSplitter &ts, char *name, int id);
const char *name() const { return name_.c_str(); }
const int id() const { return id_; }
const int type() const { return 0; } // FIXME: Implement type de-masking
bool isPointInSector(Vector3d point) const {
// FIXME: Implement point-in-poly function
return false;
}
private:
int numVertices_, id_;
std::string name_;
int type_;
std::string visibility_;
Vector3d *vertices_;
float height_;
};
#endif