Skip to content

Commit

Permalink
Implement metaroom background changing
Browse files Browse the repository at this point in the history
TODO: supposed to be per-camera? wonder if that's actually true
  • Loading branch information
ligfx committed May 11, 2021
1 parent 47422ab commit bd2aad2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
26 changes: 16 additions & 10 deletions src/MetaRoom.cpp
Expand Up @@ -51,6 +51,7 @@ void MetaRoom::addBackground(std::string back) {
firstback = back;
fullwid = totalwidth;
fullhei = totalheight;
current_background = back;
} else {
// make sure other backgrounds are the same size
if (engine.gametype == "sm")
Expand All @@ -69,18 +70,23 @@ std::vector<std::string> MetaRoom::backgroundList() {
return b;
}

std::shared_ptr<creaturesImage> MetaRoom::getBackground(std::string back) {
// return the first background by default
if (back.empty()) {
return backgrounds[firstback];
}
std::shared_ptr<creaturesImage> MetaRoom::getCurrentBackground() {
return backgrounds[current_background];
}

// if this background name isn't found, return null
if (backgrounds.find(back) != backgrounds.end())
return std::shared_ptr<creaturesImage>();
std::string MetaRoom::getCurrentBackgroundName() const {
return current_background;
}

bool MetaRoom::hasBackground(std::string back) const {
return backgrounds.find(back) != backgrounds.end();
}

// otherwise, return the relevant background
return backgrounds[back];
void MetaRoom::setBackground(std::string back) {
// TODO: supposedly the current background is per-camera
// TODO: camera transition effects??
assert(hasBackground(back));
current_background = back;
}

MetaRoom::~MetaRoom() {
Expand Down
7 changes: 6 additions & 1 deletion src/MetaRoom.h
Expand Up @@ -37,6 +37,7 @@ class MetaRoom {
unsigned int xloc, yloc, wid, hei, fullwid, fullhei;
std::map<std::string, std::shared_ptr<creaturesImage> > backgrounds;
std::string firstback;
std::string current_background;
bool wraps;

MetaRoom() {}
Expand All @@ -54,8 +55,12 @@ class MetaRoom {
void setWraparound(bool w) { wraps = !!w; }

unsigned int addRoom(std::shared_ptr<class Room>);

void addBackground(std::string);
std::shared_ptr<creaturesImage> getBackground(std::string);
bool hasBackground(std::string) const;
void setBackground(std::string);
std::shared_ptr<creaturesImage> getCurrentBackground();
std::string getCurrentBackgroundName() const;
std::vector<std::string> backgroundList();

std::shared_ptr<Room> nextFloorFromPoint(float x, float y);
Expand Down
3 changes: 2 additions & 1 deletion src/World.cpp
Expand Up @@ -404,7 +404,8 @@ void World::drawWorld(Camera* cam, RenderTarget* surface) {
}
int adjustx = cam->getX();
int adjusty = cam->getY();
std::shared_ptr<creaturesImage> bkgd = m->getBackground(""); // TODO
// TODO: current backgrounds is per camera (supposedly?)
std::shared_ptr<creaturesImage> bkgd = m->getCurrentBackground();

// TODO: work out what c2e does when it doesn't have a background..
if (!bkgd)
Expand Down
17 changes: 12 additions & 5 deletions src/caos/caosVM_camera.cpp
Expand Up @@ -465,7 +465,13 @@ void v_LOFT(caosVM* vm) {

/**
BKGD (command) metaroom_id (integer) background (string) transition (integer)
%status stub
%status maybe
Changes the current background displayed for the selected camera (with SCAM).
Transition is as for META. The background must have been specified with the ADDM
or ADDB command first.
TODO: track different backgrounds per metaroom per camera
*/
void c_BKGD(caosVM* vm) {
VM_PARAM_INTEGER(transition)
Expand All @@ -474,8 +480,10 @@ void c_BKGD(caosVM* vm) {

MetaRoom* metaroom = world.map->getMetaRoom(metaroomid);
caos_assert(metaroom);

// TODO
caos_assert(background.size());
caos_assert(metaroom->hasBackground(background));
caos_assert(transition == 0);
metaroom->setBackground(background);
}

/**
Expand All @@ -487,8 +495,7 @@ void v_BKGD(caosVM* vm) {

MetaRoom* metaroom = world.map->getMetaRoom(metaroomid);
caos_assert(metaroom);

vm->result.setString(""); // TODO
vm->result.setString(metaroom->getCurrentBackgroundName());
}

/**
Expand Down

0 comments on commit bd2aad2

Please sign in to comment.