From: Matthijs Kooijman Date: Mon, 11 Jun 2007 18:15:24 +0000 (+0200) Subject: * Make CEngine keep a CSpriteManager. X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2FABM2.git;a=commitdiff_plain;h=887e744e425c6c25fcfdbad863d3c9287ad91d93 * Make CEngine keep a CSpriteManager. * Let VideoUpdate create its Graphics object in ctor instead of Start, so it is available for Sprite creation. * Make VideoUpdate start and end scenes appropriately, so always a scene is open. * Add a CSpriteManager that loads default sprites. --- diff --git a/ABM2/Engine/Kernel.h b/ABM2/Engine/Kernel.h index 0e1c39d..3eda3db 100755 --- a/ABM2/Engine/Kernel.h +++ b/ABM2/Engine/Kernel.h @@ -10,6 +10,7 @@ #endif // _MSC_VER > 1000 #include "singleton.h" +#include "SpriteManager.h" class CClient; @@ -30,10 +31,13 @@ public: void ResumeTask(const CMMPointer &t); void RemoveTask(const CMMPointer &t); void KillAllTasks(); - + + void setSpriteManager(CSpriteManager*) {this->sm = sm;} + CSpriteManager* getSpriteManager() {return this->sm;} protected: std::list< CMMPointer > taskList; std::list< CMMPointer > pausedTaskList; + CSpriteManager *sm; }; class ITask : public IMMObject diff --git a/ABM2/Engine/VideoUpdate.cpp b/ABM2/Engine/VideoUpdate.cpp index 270a67b..1d66b9c 100755 --- a/ABM2/Engine/VideoUpdate.cpp +++ b/ABM2/Engine/VideoUpdate.cpp @@ -26,6 +26,8 @@ int CVideoUpdate::scrBPP=16; CVideoUpdate::CVideoUpdate() { + assert(screenWidth && screenHeight && screenBPP); + this->g = new Graphics(scrWidth, scrHeight, 16, false); } CVideoUpdate::~CVideoUpdate() @@ -34,7 +36,6 @@ CVideoUpdate::~CVideoUpdate() bool CVideoUpdate::Start() { - assert(screenWidth && screenHeight && screenBPP); /* if(-1==SDL_InitSubSystem(SDL_INIT_VIDEO)) { @@ -59,24 +60,25 @@ bool CVideoUpdate::Start() //hide the mouse cursor SDL_ShowCursor(SDL_DISABLE); */ - this->g = new Graphics(scrWidth, scrHeight, 16, false); if (this->g->createDisplay()) return false; this->g->setCullingMode(AM_CULL_NONE); this->g->setBackground(COLOUR_RGBA(127, 127, 127, 255)); - - this->s = new Sprite("Data/POWBOMB.png", COLOUR_RGBA(0, 0, 255, 255), 64, 64, this->g); + + /* Start a first scene */ + this->g->beginScene(); return true; } void CVideoUpdate::Update() { - this->g->beginScene(); - this->s->blit(0, 0, 1.0, 1.0, 0, 0, COLOUR_RGBA(255, 255, 255, 255)); this->g->endScene(); + this->g->beginScene(); } void CVideoUpdate::Stop() { + /* End the last scene */ + this->g->endScene(); delete this->g; } diff --git a/ABM2/Engine/VideoUpdate.h b/ABM2/Engine/VideoUpdate.h index e0f4bc2..0bf5d4d 100755 --- a/ABM2/Engine/VideoUpdate.h +++ b/ABM2/Engine/VideoUpdate.h @@ -9,17 +9,9 @@ #pragma once #endif // _MSC_VER > 1000 -#ifdef WITH_SDL #include #include -#else // WITH_SDL -#include -#include - -#include "engine.h" -extern LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class -#endif // WITH_SDL class CVideoUpdate : public ITask { @@ -34,13 +26,10 @@ public: bool Start(); void Update(); void Stop(); + + Graphics* getGraphics() { return this->g; } private: -#ifdef WITH_SDL Graphics *g; - Sprite *s; -#else - LPDIRECT3D9 d3d; // the pointer to our Direct3D interface -#endif //WITH_SDL }; #endif // !defined(AFX_VIDEOUPDATE_H__FB4B263B_4FA7_4700_BB70_EE5CB1768E83__INCLUDED_) diff --git a/ABM2/Makefile b/ABM2/Makefile index 91782ea..d3b2d61 100644 --- a/ABM2/Makefile +++ b/ABM2/Makefile @@ -5,7 +5,7 @@ OBJS := main.o Engine/Log.o SchemeReader.o Engine/Settings.o \ Engine/mmanager.o Engine/Kernel.o Engine/ProfileLogHandler.o \ Engine/VideoUpdate.o Engine/GlobalTimer.o Engine/SoundTask.o \ Engine/profiler.o Playground.o Engine/InputTask.o \ - Amaltheia/Graphics.o Amaltheia/Sprite.o + Amaltheia/Graphics.o Amaltheia/Sprite.o Engine/SpriteManager.o #include these in linking. Linking with -lftgl doesn't work for some stupid reason... EXTRA_OBJS := /usr/lib/libftgl.a diff --git a/ABM2/main.cpp b/ABM2/main.cpp index 48dcd73..e325647 100755 --- a/ABM2/main.cpp +++ b/ABM2/main.cpp @@ -6,6 +6,7 @@ #include "Engine/engine.h" #include "Engine/game.h" +#include "Engine/SpriteManager.h" #include "Playground.h" #include "SchemeReader.h" @@ -13,6 +14,21 @@ #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 +enum SpriteID { + SPR_NONE = 0, + SPR_FIELD, + SPR_SOLID, + SPR_BRICK, + SPR_BLANK, + SPR_PLAYER, +}; + +SpriteData defaultSprites[] = { + {SPR_FIELD, "FIELD0.png", 640, 480}, + {SPR_BLANK, "FIELD0.png", 640, 480}, + {SPR_NONE, NULL, 0, 0} +}; + #ifdef WIN32 HINSTANCE hInstance; HWND hWnd; @@ -155,6 +171,9 @@ void CApplication::Run(int argc, char *argv[]) globalTimer->priority=10; CKernel::GetSingleton().AddTask(CMMPointer(globalTimer)); + CSpriteManager *sm = new CSpriteManager(videoTask->getGraphics(), defaultSprites); + CKernel::GetSingleton().setSpriteManager(sm); + Playground game; game.priority=100; CKernel::GetSingleton().AddTask(CMMPointer(&game));