Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,231 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_BINTREE_H
#define HPL_BINTREE_H
#include "common/list.h"
namespace hpl {
enum eBinTreeNode {
eBinTreeNode_Left,
eBinTreeNode_Right
};
//////////////////////////////////////////////////////////////////////////
// TREE NODE CLASS
//////////////////////////////////////////////////////////////////////////
template<class T>
class BinTreeNode {
public:
T *GetData() {
return &mData;
}
BinTreeNode(T aData, BinTreeNode<T> *aParent, eBinTreeNode aParentDir) {
for (int i = 0; i < 2; i++)
mChild[i] = NULL;
mData = aData;
mParent = aParent;
mParentDir = aParentDir;
}
BinTreeNode<T> *AddChild(eBinTreeNode i, T aData) {
if (mChild[i] == NULL) {
mChild[i] = hplNew(BinTreeNode<T>, (aData, this, i));
return mChild[i];
}
return NULL;
}
BinTreeNode<T> *GetChild(eBinTreeNode i) {
return mChild[i];
}
BinTreeNode<T> *GetParent() {
return mParent;
}
private:
BinTreeNode<T> *mChild[2];
BinTreeNode<T> *mParent;
T mData;
eBinTreeNode mParentDir;
};
//////////////////////////////////////////////////////////////////////////
// MAIN TREE CLASS
//////////////////////////////////////////////////////////////////////////
template<class T>
class BinTree {
public:
BinTree() {
mlNumOfNodes = 0;
mFirstNode = NULL;
}
~BinTree() {
Clear();
}
/**
* Clears the entire tree
* \return number of nodes deleted
*/
int Clear() {
mlNum = 0;
DeleteNode(mFirstNode);
mFirstNode = NULL;
return mlNum;
}
/**
* Insert a node to the tree.
* \todo only works to set the root node.
* \param aData the data to insert
* \return
*/
BinTreeNode<T> *Insert(T aData) {
if (mFirstNode == NULL) {
mFirstNode = hplNew(BinTreeNode<T>, (aData, NULL, eBinTreeNode_Left));
mlNumOfNodes++;
return mFirstNode;
}
// Insertion other then at the root is not supported!
BinTreeNode<T> *Node = mFirstNode;
eBinTreeNode c;
while (true) {
// if(Node->GetData()<aData)
c = eBinTreeNode_Left;
// else
// c = eBinTreeNode_Right;
if (Node->GetChild(c) == NULL) {
Node = Node->AddChild(c, aData);
break;
} else {
Node = Node->GetChild(c);
}
}
mlNumOfNodes++;
return Node;
}
/**
* Insert a node into a certain node in the tree
* \param aData the data to insert
* \param aNode the node to insert the data in
* \param aChild what child to insert at
* \return
*/
BinTreeNode<T> *InsertAt(T aData, BinTreeNode<T> *aNode, eBinTreeNode aChild = eBinTreeNode_Left) {
if (aNode == NULL)
return NULL;
if (aNode->GetChild(aChild) != NULL) {
aChild = aChild == eBinTreeNode_Left ? eBinTreeNode_Right : eBinTreeNode_Left;
if (aNode->GetChild(aChild) != NULL)
return NULL;
}
return aNode->AddChild(aChild, aData);
}
/**
* Get the size of the tree
* \return
*/
int Size() {
return mlNumOfNodes;
}
const Common::List<BinTreeNode<T> *> &GetLeafList() {
mlstNodes.clear();
PopulateLeafList(mFirstNode);
return mlstNodes;
}
/**
* Get a list of all the nodes in the tree
* \return
*/
const Common::List<BinTreeNode<T> *> &GetNodeList() {
mlstNodes.clear();
PopulateNodeList(mFirstNode);
return mlstNodes;
}
private:
int mlNumOfNodes;
BinTreeNode<T> *mFirstNode;
int mlNum;
Common::List<BinTreeNode<T> *> mlstNodes;
void DeleteNode(BinTreeNode<T> *aNode) {
if (aNode == NULL)
return;
DeleteNode(aNode->GetChild(eBinTreeNode_Left));
DeleteNode(aNode->GetChild(eBinTreeNode_Right));
hplDelete(aNode);
mlNum++;
}
void PopulateNodeList(BinTreeNode<T> *aNode) {
if (aNode == NULL)
return;
PopulateNodeList(aNode->GetChild(eBinTreeNode_Left));
mlstNodes.push_back(aNode);
PopulateNodeList(aNode->GetChild(eBinTreeNode_Right));
}
void PopulateLeafList(BinTreeNode<T> *aNode) {
if (aNode == NULL)
return;
if (aNode->GetChild(eBinTreeNode_Left) == NULL &&
aNode->GetChild(eBinTreeNode_Right) == NULL) {
mlstNodes.push_back(aNode);
}
PopulateLeafList(aNode->GetChild(eBinTreeNode_Left));
PopulateLeafList(aNode->GetChild(eBinTreeNode_Right));
}
};
} // namespace hpl
#endif // HPL_BINTREE_H

View File

@@ -0,0 +1,56 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/system/Container.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,264 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_CONTAINER_H
#define HPL_CONTAINER_H
#include "common/array.h"
#include "common/list.h"
#include "hpl1/engine/system/MemoryManager.h"
#include "common/stablemap.h"
namespace hpl {
//---------------------------------
class iContainerIterator {
friend class cSerializeClass;
public:
virtual ~iContainerIterator() {}
protected:
virtual bool HasNext() = 0;
virtual void *NextPtr() = 0;
};
//---------------------------------
class iContainer {
friend class cSerializeClass;
public:
virtual ~iContainer() = default;
virtual size_t Size() = 0;
virtual void Clear() = 0;
protected:
virtual void AddVoidPtr(void **apPtr) = 0;
virtual void AddVoidClass(void *apClass) = 0;
virtual iContainerIterator *CreateIteratorPtr() = 0;
};
//---------------------------------
class iContainerKeyPair {
public:
virtual ~iContainerKeyPair() = default;
virtual size_t Size() = 0;
virtual void AddVoidPtr(void *apKey, void **apClass) = 0;
virtual void AddVoidClass(void *apKey, void *apClass) = 0;
};
//---------------------------------
template<class T>
class cContainerVecIterator : public iContainerIterator {
void *NextPtr() {
return &Next();
}
public:
cContainerVecIterator(Common::Array<T> *apVec) {
mpVec = apVec;
mIt = apVec->begin();
}
bool HasNext() {
return mIt != mpVec->end();
}
T &Next() {
T &val = *mIt;
mIt++;
return val;
}
T &PeekNext() {
return *mIt;
}
void Erase() {
if (mIt != mpVec->end())
mIt = mpVec->erase(mIt);
}
private:
Common::Array<T> *mpVec;
typename Common::Array<T>::iterator mIt;
};
////////////////////////////
template<class T>
class cContainerVec : public iContainer {
private:
void AddVoidPtr(void **apPtr) {
mvVector.push_back(*((T *)apPtr));
}
void AddVoidClass(void *apClass) {
mvVector.push_back(*((T *)apClass));
}
iContainerIterator *CreateIteratorPtr() {
return hplNew(cContainerVecIterator<T>, (&mvVector));
}
public:
cContainerVec() {}
//////////////////////
size_t Size() {
return mvVector.size();
}
void Clear() {
mvVector.clear();
}
//////////////////////
void Reserve(size_t alSize) {
mvVector.reserve(alSize);
}
void Resize(size_t alSize) {
mvVector.resize(alSize);
}
void Add(T aVal) {
mvVector.push_back(aVal);
}
//////////////////////
cContainerVecIterator<T> GetIterator() {
return cContainerVecIterator<T>(&mvVector);
}
//////////////////////
T &operator[](size_t alX) {
return mvVector[alX];
}
//////////////////////
Common::Array<T> mvVector;
};
//---------------------------------
template<class T>
class cContainerListIterator : public iContainerIterator {
void *NextPtr() {
return &Next();
}
public:
cContainerListIterator(Common::List<T> *apVec) {
mpVec = apVec;
mIt = apVec->begin();
}
virtual ~cContainerListIterator() {}
bool HasNext() {
return mIt != mpVec->end();
}
T &Next() {
T &val = *mIt;
mIt++;
return val;
}
T &PeekNext() {
return *mIt;
}
void Erase() {
if (mIt != mpVec->end())
mIt = mpVec->erase(mIt);
}
private:
Common::List<T> *mpVec;
typename Common::List<T>::iterator mIt;
};
////////////////////////////
template<class T>
class cContainerList : public iContainer {
private:
void AddVoidPtr(void **apPtr) {
mvVector.push_back(*((T *)apPtr));
}
void AddVoidClass(void *apClass) {
mvVector.push_back(*((T *)apClass));
}
iContainerIterator *CreateIteratorPtr() {
return hplNew(cContainerListIterator<T>, (&mvVector));
}
public:
cContainerList() {}
virtual ~cContainerList() {}
//////////////////////
size_t Size() {
return mvVector.size();
}
void Clear() {
mvVector.clear();
}
//////////////////////
void Add(T aVal) {
mvVector.push_back(aVal);
}
//////////////////////
cContainerListIterator<T> GetIterator() {
return cContainerListIterator<T>(&mvVector);
}
//////////////////////
Common::List<T> mvVector;
};
//---------------------------------
} // namespace hpl
#endif // HPL_CONTAINER_H

View File

@@ -0,0 +1,127 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/system/LogicTimer.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cLogicTimer::cLogicTimer(int alUpdatesPerSec, LowLevelSystem *apLowLevelSystem) {
mlMaxUpdates = alUpdatesPerSec;
mlUpdateCount = 0;
mpLowLevelSystem = apLowLevelSystem;
SetUpdatesPerSec(alUpdatesPerSec);
}
//-----------------------------------------------------------------------
cLogicTimer::~cLogicTimer() {
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
void cLogicTimer::Reset() {
mlLocalTime = (double)GetApplicationTime();
}
//-----------------------------------------------------------------------
bool cLogicTimer::WantUpdate() {
++mlUpdateCount;
if (mlUpdateCount > mlMaxUpdates)
return false;
if (mlLocalTime < (double)GetApplicationTime()) {
Update();
return true;
}
return false;
}
//-----------------------------------------------------------------------
void cLogicTimer::EndUpdateLoop() {
if (mlUpdateCount > mlMaxUpdates) {
Reset();
}
mlUpdateCount = 0;
}
//-----------------------------------------------------------------------
void cLogicTimer::SetUpdatesPerSec(int alUpdatesPerSec) {
mlLocalTimeAdd = 1000.0 / ((double)alUpdatesPerSec);
Reset();
}
//-----------------------------------------------------------------------
void cLogicTimer::SetMaxUpdates(int alMax) {
mlMaxUpdates = alMax;
}
//-----------------------------------------------------------------------
int cLogicTimer::GetUpdatesPerSec() {
return (int)(1000.0 / ((double)mlLocalTimeAdd));
}
//-----------------------------------------------------------------------
float cLogicTimer::GetStepSize() {
return ((float)mlLocalTimeAdd) / 1000.0f;
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
void cLogicTimer::Update() {
mlLocalTime += mlLocalTimeAdd;
}
//-----------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,96 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_LOGICTIMER_H
#define HPL_LOGICTIMER_H
namespace hpl {
class LowLevelSystem;
class cLogicTimer {
public:
/**
*
* \param alUpdatesPerSec Number of updates per second.
* \param *apLowLevelSystem
* \return
*/
cLogicTimer(int alUpdatesPerSec, LowLevelSystem *apLowLevelSystem);
~cLogicTimer();
/**
* Reset the time. Do this when the logical update of the game has been ide, ie while loading.
*/
void Reset();
/**
* Check with the time if it is time for another logical update
* \return true if logic should be updated, else false.
*/
bool WantUpdate();
/**
* Resets various variables that makes the graphics is never frozen.
*/
void EndUpdateLoop();
/**
* Set the number of times per second to update
* \param alUpdatesPerSec
*/
void SetUpdatesPerSec(int alUpdatesPerSec);
/**
* Sets the maximum updates in a row.
* \param alUpdatesPerSec
*/
void SetMaxUpdates(int alMax);
/**
* Get the number of updates per second.
*/
int GetUpdatesPerSec();
/**
* Get the size of each step in seconds.
*/
float GetStepSize();
private:
void Update();
double mlLocalTime;
double mlLocalTimeAdd;
int mlMaxUpdates;
int mlUpdateCount;
LowLevelSystem *mpLowLevelSystem;
};
} // namespace hpl
#endif // HPL_LOGICTIMER_H

View File

@@ -0,0 +1,52 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_MEMORY_MANAGER_H
#define HPL_MEMORY_MANAGER_H
#include "common/str.h"
#include "common/stablemap.h"
#define hplNew(classType, constructor) \
new classType constructor
#define hplNewArray(classType, amount) \
new classType[amount]
#define hplMalloc(amount) \
malloc(amount)
#define hplDelete(data) \
delete data;
#define hplDeleteArray(data) \
delete[] data;
#define hplFree(data) \
free(data);
#endif // HPL_MEMORY_MANAGER_H

View File

@@ -0,0 +1,250 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_SCRIPT_H
#define HPL_SCRIPT_H
#include "hpl1/engine/resources/ResourceBase.h"
// Script Macros to build Generic wrappers if necessary
#define SCRIPT_DEFINE_FUNC(return, funcname) \
SCRIPT_FUNC_BEGIN(funcname, return, "") \
SCRIPT_RETURN_CALL_##return funcname(); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_1(return, funcname, arg0) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_RETURN_CALL_##return funcname(_arg0); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_2(return, funcname, arg0, arg1) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_3(return, funcname, arg0, arg1, arg2) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_4(return, funcname, arg0, arg1, arg2, arg3) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_5(return, funcname, arg0, arg1, arg2, arg3, arg4) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_6(return, funcname, arg0, arg1, arg2, arg3, arg4, arg5) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4 "," #arg5) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_ARG_##arg5(5); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_7(return, funcname, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4 "," #arg5 "," #arg6) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_ARG_##arg5(5); \
SCRIPT_ARG_##arg6(6); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_8(return, funcname, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4 "," #arg5 "," #arg6 "," #arg7) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_ARG_##arg5(5); \
SCRIPT_ARG_##arg6(6); \
SCRIPT_ARG_##arg7(7); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_9(return, funcname, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4 "," #arg5 "," #arg6 "," #arg7 "," #arg8) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_ARG_##arg5(5); \
SCRIPT_ARG_##arg6(6); \
SCRIPT_ARG_##arg7(7); \
SCRIPT_ARG_##arg8(8); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_10(return, funcname, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4 "," #arg5 "," #arg6 "," #arg7 "," #arg8 "," #arg9) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_ARG_##arg5(5); \
SCRIPT_ARG_##arg6(6); \
SCRIPT_ARG_##arg7(7); \
SCRIPT_ARG_##arg8(8); \
SCRIPT_ARG_##arg9(9); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_12(return, funcname, arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
arg7, arg8, arg9, arg10, arg11) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4 "," #arg5 "," #arg6 "," #arg7 "," #arg8 "," #arg9 "," #arg10 "," #arg11) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_ARG_##arg5(5); \
SCRIPT_ARG_##arg6(6); \
SCRIPT_ARG_##arg7(7); \
SCRIPT_ARG_##arg8(8); \
SCRIPT_ARG_##arg9(9); \
SCRIPT_ARG_##arg10(10); \
SCRIPT_ARG_##arg11(11); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, \
_arg7, _arg8, _arg9, _arg10, _arg11); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_DEFINE_FUNC_17(return, funcname, arg0, arg1, arg2, arg3, arg4, arg5, arg6, \
arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16) \
SCRIPT_FUNC_BEGIN(funcname, return, #arg0 "," #arg1 "," #arg2 "," #arg3 "," #arg4 "," #arg5 "," #arg6 "," #arg7 "," #arg8 "," #arg9 "," #arg10 "," #arg11 "," #arg12 "," #arg13 "," #arg14 "," #arg15 "," #arg16) \
SCRIPT_ARG_##arg0(0); \
SCRIPT_ARG_##arg1(1); \
SCRIPT_ARG_##arg2(2); \
SCRIPT_ARG_##arg3(3); \
SCRIPT_ARG_##arg4(4); \
SCRIPT_ARG_##arg5(5); \
SCRIPT_ARG_##arg6(6); \
SCRIPT_ARG_##arg7(7); \
SCRIPT_ARG_##arg8(8); \
SCRIPT_ARG_##arg9(9); \
SCRIPT_ARG_##arg10(10); \
SCRIPT_ARG_##arg11(11); \
SCRIPT_ARG_##arg12(12); \
SCRIPT_ARG_##arg13(13); \
SCRIPT_ARG_##arg14(14); \
SCRIPT_ARG_##arg15(15); \
SCRIPT_ARG_##arg16(16); \
SCRIPT_RETURN_CALL_##return funcname(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, \
_arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14, _arg15, _arg16); \
SCRIPT_FUNC_END(funcname, return )
#define SCRIPT_FUNC_BEGIN(funcname, return, args) \
namespace GenericScript { \
static const char *funcname##_return = #return; \
static const char *funcname##_arg = args; \
void funcname##_Generic(asIScriptGeneric * gen) { \
SCRIPT_RETURN_##return;
#define SCRIPT_FUNC_END(funcname, return ) \
SCRIPT_SET_RETURN_##return; \
} \
}
// Parameter Macros
// FIXME: string types
#define SCRIPT_ARG_string(n) tString _arg##n = (*(Common::String *)gen->GetArgObject(n))
#define SCRIPT_ARG_float(n) float _arg##n = gen->GetArgFloat(n)
#define SCRIPT_ARG_int(n) int _arg##n = gen->GetArgDWord(n)
#define SCRIPT_ARG_bool(n) bool _arg##n = gen->GetArgByte(n)
// Return Value Macros
#define SCRIPT_RETURN_string tString _ret
#define SCRIPT_RETURN_CALL_string _ret =
#define SCRIPT_SET_RETURN_string gen->SetReturnObject(&_ret)
#define SCRIPT_RETURN_bool bool _ret
#define SCRIPT_RETURN_CALL_bool _ret =
#define SCRIPT_SET_RETURN_bool gen->SetReturnByte(_ret ? -1 : 0)
#define SCRIPT_RETURN_int int _ret
#define SCRIPT_RETURN_CALL_int _ret =
#define SCRIPT_SET_RETURN_int gen->SetReturnDWord(_ret)
#define SCRIPT_RETURN_float float _ret
#define SCRIPT_RETURN_CALL_float _ret =
#define SCRIPT_SET_RETURN_float gen->SetReturnFloat(_ret)
#define SCRIPT_RETURN_void
#define SCRIPT_RETURN_CALL_void
#define SCRIPT_SET_RETURN_void
#define AS_MAX_PORTABILITY
#if defined(AS_MAX_PORTABILITY)
#define SCRIPT_REGISTER_FUNC(funcname) \
Common::String(GenericScript::funcname##_return) + " " + Common::String(#funcname) + " (" + Common::String(GenericScript::funcname##_arg) + ")", GenericScript::funcname##_Generic, asCALL_GENERIC
#else
#define SCRIPT_REGISTER_FUNC(funcname) \
GenericScript::funcname##_return + " " #funcname " (" + GenericScript::funcname##_arg + ")", (void *)funcname, asCALL_STDCALL
#endif
namespace hpl {
class iScript : public iResourceBase {
public:
iScript(const tString &asName) : iResourceBase(asName, 0) {}
virtual ~iScript() {}
bool reload() { return false; }
void unload() {}
void destroy() {}
virtual bool CreateFromFile(const tString &asFile) = 0;
virtual int GetFuncHandle(const tString &asFunc) = 0;
virtual void AddArg(const tString &asArg) = 0;
/**
* Runs a func in the script, for example "test(15)"
* \param asFuncLine the line of code
* \return true if everything was ok, else false
*/
virtual bool Run(const tString &asFuncLine) = 0;
virtual bool Run(int alHandle) = 0;
};
} // namespace hpl
#endif // HPL_SCRIPT_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,338 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_SERIALIZE_CLASS_H
#define HPL_SERIALIZE_CLASS_H
#include "hpl1/engine/system/MemoryManager.h"
#include "hpl1/engine/system/SystemTypes.h"
#include "hpl1/static_string.h"
#include "common/stablemap.h"
class TiXmlElement;
namespace hpl {
/////////////////////////////////////////////////
//// ENGINE VALUE TYPES ///////////////////////////////
/////////////////////////////////////////////////
typedef unsigned int eSerializeType;
#define eSerializeType_Bool (1)
#define eSerializeType_Int32 (2)
#define eSerializeType_Float32 (3)
#define eSerializeType_String (4)
#define eSerializeType_Vector2l (5)
#define eSerializeType_Vector2f (6)
#define eSerializeType_Vector3l (7)
#define eSerializeType_Vector3f (8)
#define eSerializeType_Matrixf (9)
#define eSerializeType_Color (10)
#define eSerializeType_Rect2l (11)
#define eSerializeType_Rect2f (12)
#define eSerializeType_Planef (13)
#define eSerializeType_WString (14)
#define eSerializeType_Class (100)
// Important with this type is that it will only be created
// if the member variable is NULL. Else it is assume that it is
// already created.
// Also, for the class to be a class pointer it has to have a
// constructor without any parameters.
// NULL Values are NOT allowed!
#define eSerializeType_ClassPointer (101)
// User defined types must be after this
#define eSerializeType_Last (200)
#define eSerializeType_NULL (0xFFFF)
/////////////////////////////////////////////////
//// ENGINE MAIN TYPES //////////////////////////
/////////////////////////////////////////////////
typedef unsigned int eSerializeMainType;
#define eSerializeMainType_Variable (1)
#define eSerializeMainType_Array (2)
#define eSerializeMainType_Container (3)
#define eSerializeMainType_NULL (0xFFFF)
/////////////////////////////////////////////////
//// HELPER DEFINES /////////////////////////////
/////////////////////////////////////////////////
#define ClassMemberOffset(aClass, aMember) (size_t(&(((aClass *)1)->aMember)) - 1)
#define ClassMemberSize(aClass, aMember) (sizeof(((aClass *)1)->aMember))
/**
* This inits a class and must be first in a serializable class
*/
#define kSerializableClassInit(aClass) \
public: \
const static char *msSerialize_Name; \
const static char *msSerialize_ParentName; \
static cSerializeMemberField *mpSerialize_MemberFields; \
virtual ~aClass() = default; \
virtual tString Serialize_GetTopClass() { return #aClass; }
#define kSerializableClassInit_nodestructor(aClass) \
public: \
const static char *msSerialize_Name; \
const static char *msSerialize_ParentName; \
static cSerializeMemberField *mpSerialize_MemberFields; \
virtual tString Serialize_GetTopClass() { return #aClass; }
/**
* Declared in the cpp-file of the class to be serialized. Class must have parent!
*/
#define kBeginSerialize(aClass, aParent) \
namespace SerializeNamespace_##aClass { \
extern cSerializeMemberField mvTempMemberFields[]; \
} \
const char *aClass::msSerialize_Name = #aClass; \
const char *aClass::msSerialize_ParentName = #aParent; \
cSerializeMemberField *aClass::mpSerialize_MemberFields = SerializeNamespace_##aClass::mvTempMemberFields; \
namespace SerializeNamespace_##aClass { \
typedef aClass tVarClass; \
cSerializeMemberField mvTempMemberFields[] = {
#define kBeginSerializeBase(aClass) \
namespace SerializeNamespace_##aClass { \
extern cSerializeMemberField mvTempMemberFields[]; \
} \
const char *aClass::msSerialize_Name = #aClass; \
const char *aClass::msSerialize_ParentName = ""; \
cSerializeMemberField *aClass::mpSerialize_MemberFields = SerializeNamespace_##aClass::mvTempMemberFields; \
namespace SerializeNamespace_##aClass { \
typedef aClass tVarClass; \
cSerializeMemberField mvTempMemberFields[] = {
#define kBeginSerializeVirtual(aClass, aParent) \
namespace SerializeNamespace_##aClass { \
extern cSerializeMemberField mvTempMemberFields[]; \
} \
const char *aClass::msSerialize_Name = #aClass; \
const char *aClass::msSerialize_ParentName = #aParent; \
cSerializeMemberField *aClass::mpSerialize_MemberFields = SerializeNamespace_##aClass::mvTempMemberFields; \
namespace SerializeNamespace_##aClass { \
typedef aClass tVarClass; \
cSerializeMemberField mvTempMemberFields[] = {
#define kBeginSerializeBaseVirtual(aClass) \
namespace SerializeNamespace_##aClass { \
extern cSerializeMemberField mvTempMemberFields[]; \
} \
const char *aClass::msSerialize_Name = #aClass; \
const char *aClass::msSerialize_ParentName = ""; \
cSerializeMemberField *aClass::mpSerialize_MemberFields = SerializeNamespace_##aClass::mvTempMemberFields; \
namespace SerializeNamespace_##aClass { \
typedef aClass tVarClass; \
cSerializeMemberField mvTempMemberFields[] = {
/**
*Declared when all variable declarations are over.
*/
#define kEndSerialize() \
cSerializeMemberField("", 0, 0, eSerializeType_NULL, 0) \
} \
; \
}
/**
* Declared after begin, adds a variable or class.
*/
#define kSerializeVar(aVar, aType) \
cSerializeMemberField(#aVar, ClassMemberOffset(tVarClass, aVar), ClassMemberSize(tVarClass, aVar), aType, eSerializeMainType_Variable),
/**
* Declared after begin, adds an array of variables.
*/
#define kSerializeVarArray(aVar, aType, aArraySize) \
cSerializeMemberField(#aVar, ClassMemberOffset(tVarClass, aVar), ClassMemberSize(tVarClass, aVar), aType, eSerializeMainType_Array, aArraySize),
/**
* Declared after begin, adds an container of variables.
*/
#define kSerializeVarContainer(aVar, aType) \
cSerializeMemberField(#aVar, ClassMemberOffset(tVarClass, aVar), ClassMemberSize(tVarClass, aVar), aType, eSerializeMainType_Container),
/**
* Declared after begin, adds an container of classes.
*/
#define kSerializeClassContainer(aVar, aClass, aType) \
cSerializeMemberField(#aVar, ClassMemberOffset(tVarClass, aVar), ClassMemberSize(tVarClass, aVar), aType, eSerializeMainType_Container, #aClass),
/////////////////////////////////////////////////
//// CLASSES ////////////////////////////////////
/////////////////////////////////////////////////
//-------------------------------------------------
class cSerializeMemberField {
public:
constexpr cSerializeMemberField(Hpl1::StaticString asName, size_t alOffset, size_t alSize, eSerializeType alType,
eSerializeMainType aMainType) : msName(asName), msClassName(""), mlOffset(alOffset), mlSize(alSize), mType(alType), mMainType(aMainType), mlArraySize(0) {
}
constexpr cSerializeMemberField(Hpl1::StaticString asName, size_t alOffset, size_t alSize, eSerializeType alType,
eSerializeMainType aMainType, size_t alArraySize) : msName(asName), msClassName(""), mlOffset(alOffset), mlSize(alSize), mType(alType), mMainType(aMainType), mlArraySize(alArraySize) {
}
constexpr cSerializeMemberField(Hpl1::StaticString asName, size_t alOffset, size_t alSize, eSerializeType alType,
eSerializeMainType aMainType, Hpl1::StaticString asClassName) : msName(asName), msClassName(asClassName), mlOffset(alOffset), mlSize(alSize), mType(alType), mMainType(aMainType), mlArraySize(0) {
}
Hpl1::StaticString msName;
Hpl1::StaticString msClassName;
size_t mlOffset;
size_t mlSize;
eSerializeType mType;
eSerializeMainType mMainType;
size_t mlArraySize;
};
//-------------------------------------------------
class iSerializable {
public:
virtual ~iSerializable() = default;
virtual tString Serialize_GetTopClass() { return ""; }
};
//-------------------------------------------------
class iSerializableType {
public:
virtual ~iSerializableType() = default;
virtual char *ValueToString(void *apVal) = 0;
virtual void ValueFromString(char *apString, void *apVal) = 0;
};
//-------------------------------------------------
struct cSerializeSavedClass {
public:
constexpr cSerializeSavedClass() = default;
constexpr cSerializeSavedClass(const char *asName, const char *asParent,
cSerializeMemberField *apMemberFields, size_t alSize,
iSerializable *(*apCreateFunc)()) : msName(asName), msParentName(asParent), mpMemberFields(apMemberFields),
mlSize(alSize), mpCreateFunc(apCreateFunc) {}
const char *msName = "";
const char *msParentName = "";
cSerializeMemberField *mpMemberFields = nullptr;
size_t mlSize = 0;
iSerializable *(*mpCreateFunc)() = nullptr;
};
//-------------------------------------------------
class cSerializeMemberFieldIterator {
public:
cSerializeMemberFieldIterator(cSerializeSavedClass *apTopClass);
bool HasNext();
cSerializeMemberField *GetNext();
private:
cSerializeSavedClass *mpSavedClass;
int mlFieldNum;
};
//-------------------------------------------------
typedef Common::StableMap<Hpl1::StaticString, cSerializeSavedClass> tSerializeSavedClassMap;
typedef tSerializeSavedClassMap::iterator tSerializeSavedClassMapIt;
typedef Common::List<cSerializeSavedClass *> tSerializeSavedClassList;
typedef tSerializeSavedClassList::iterator tSerializeSavedClassListIt;
class cSerializeClass {
public:
static void initSaveClassesMap();
static void finalizeSaveClassesMap();
static void SetLog(bool abX);
static bool GetLog();
static void PrintMembers(iSerializable *apData);
static bool SaveToFile(iSerializable *apData, const tWString &asFile, const tString &asRoot);
static void SaveToElement(iSerializable *apData, const tString &asName, TiXmlElement *apParent, bool abIsPointer = false);
static bool LoadFromFile(iSerializable *apData, const tWString &asFile);
static void LoadFromElement(iSerializable *apData, TiXmlElement *apElement, bool abIsPointer = false);
static cSerializeSavedClass *GetClass(const tString &asName);
static cSerializeMemberFieldIterator GetMemberFieldIterator(iSerializable *apData);
static tString ValueToString(void *apData, size_t alOffset, eSerializeType aType);
static void StringToValue(void *apData, size_t alOffset, eSerializeType aType,
const char *asVal);
private:
static void SaveVariable(TiXmlElement *apElement, cSerializeMemberField *apField, iSerializable *apData);
static void SaveArray(TiXmlElement *apElement, cSerializeMemberField *apField, iSerializable *apData);
static void SaveContainer(TiXmlElement *apElement, cSerializeMemberField *apField, iSerializable *apData);
static void LoadVariable(TiXmlElement *apElement, iSerializable *apData, cSerializeSavedClass *apClass);
static void LoadArray(TiXmlElement *apElement, iSerializable *apData, cSerializeSavedClass *apClass);
static void LoadClass(TiXmlElement *apElement, iSerializable *apData, cSerializeSavedClass *apClass);
static void LoadClassPointer(TiXmlElement *apElement, iSerializable *apData, cSerializeSavedClass *apClass);
static void LoadContainer(TiXmlElement *apElement, iSerializable *apData, cSerializeSavedClass *apClass);
static void FillSaveClassMembersList(tSerializeSavedClassList *apList, cSerializeSavedClass *apClass);
static void SaveSavedClassMembers(cSerializeSavedClass *apClass, iSerializable *apData);
static cSerializeMemberField *GetMemberField(const tString &asName, cSerializeSavedClass *apClass);
static size_t SizeOfType(eSerializeType aType);
static void SetUpData();
static char msTempCharArray[2048];
static bool mbDataSetup;
static tSerializeSavedClassMap *m_mapSavedClasses;
static Common::Array<iSerializableType *> mvValueTypes;
};
//-------------------------------------------------
}
#endif // HPL_SERIALIZE_CLASS_H

View File

@@ -0,0 +1,646 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/system/String.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
tWString cString::To16Char(const tString &asString) {
return asString;
}
//-----------------------------------------------------------------------
tString cString::To8Char(const tWString &awsString) {
return awsString;
}
//-----------------------------------------------------------------------
tWString cString::Get16BitFromArray(const tString &asArray) {
// TODOD: needs to be rewritten to be more portal as wchar_t is not ALWAYS 2 bytes. (it's 4 on linux and os x)
tIntVec vVals;
GetIntVec(asArray, vVals, NULL);
tWString wsString;
for (auto v : vVals) {
wsString += static_cast<Common::U32String::value_type>(v);
}
return wsString;
}
//-----------------------------------------------------------------------
tString cString::Sub(const tString &asString, int alStart, int alCount) {
int lStringSize = (int)asString.size();
if (alStart >= lStringSize)
return "";
if (alStart + alCount > lStringSize)
alCount = lStringSize - alStart;
if (alCount < 0)
return asString.substr(alStart);
else
return asString.substr(alStart, alCount);
}
tWString cString::SubW(const tWString &asString, int alStart, int alCount) {
int lStringSize = (int)asString.size();
if (lStringSize == 0)
return Common::U32String("");
if (alStart >= lStringSize)
return Common::U32String("");
if (alStart + alCount > lStringSize)
alCount = lStringSize - alStart;
if (alCount < 0)
return asString.substr(alStart);
else
return asString.substr(alStart, alCount);
}
//-----------------------------------------------------------------------
// Get the file extension of a string
tString cString::GetFileExt(const tString &aString) {
int pos = GetLastStringPos(aString, ".");
if (pos < 0)
return "";
else
return aString.substr(pos + 1);
}
tWString cString::GetFileExtW(const tWString &aString) {
int pos = GetLastStringPosW(aString, Common::U32String("."));
if (pos < 0)
return Common::U32String("");
else
return aString.substr(pos + 1);
}
//-----------------------------------------------------------------------
tString cString::ToLowerCase(tString aString) {
aString.toLowercase();
return aString;
}
tWString cString::ToLowerCaseW(tWString aString) {
aString.toLowercase();
return aString;
}
//-----------------------------------------------------------------------
// Set the file extension
tString cString::SetFileExt(tString aString, tString aExt) {
if (aExt.substr(0, 1) == ".")
aExt = aExt.substr(1);
if (GetFileExt(aString) != "") {
aString = aString.substr(0, GetLastStringPos(aString, "."));
}
if (aExt != "")
aString = aString + "." + aExt;
return aString;
}
tWString cString::SetFileExtW(tWString aString, tWString aExt) {
if (aExt.substr(0, 1) == Common::U32String("."))
aExt = aExt.substr(1);
if (GetFileExtW(aString) != Common::U32String("")) {
aString = aString.substr(0, GetLastStringPosW(aString, Common::U32String(".")));
}
if (aExt != Common::U32String(""))
aString = aString + _W(".") + aExt;
return aString;
}
//-----------------------------------------------------------------------
tString cString::SetFilePath(const tString &aString, tString aPath) {
if (GetLastChar(aPath) != "/" && GetLastChar(aPath) != "\\")
aPath += "/";
auto fileName = GetFileName(aString);
return aPath + fileName;
}
tWString cString::SetFilePathW(tWString aString, tWString aPath) {
if (GetLastCharW(aPath) != _W("/") && GetLastCharW(aPath) != _W("\\"))
aPath += _W("/");
aString = GetFileNameW(aString);
return aPath + aString;
}
//-----------------------------------------------------------------------
// Gets the filename in a path
tString cString::GetFileName(const tString &aString) {
int pos1 = GetLastStringPos(aString, "\\");
int pos2 = GetLastStringPos(aString, "/");
int pos = pos1 > pos2 ? pos1 : pos2;
if (pos < 0)
return aString;
else
return aString.substr(pos + 1);
}
tWString cString::GetFileNameW(const tWString &aString) {
int pos1 = GetLastStringPosW(aString, _W("\\"));
int pos2 = GetLastStringPosW(aString, _W("/"));
int pos = pos1 > pos2 ? pos1 : pos2;
if (pos < 0)
return aString;
else
return aString.substr(pos + 1);
}
//-----------------------------------------------------------------------
tString cString::GetFilePath(const tString &aString) {
if (GetLastStringPos(aString, ".") < 0)
return aString;
int pos1 = GetLastStringPos(aString, "\\");
int pos2 = GetLastStringPos(aString, "/");
int pos = pos1 > pos2 ? pos1 : pos2;
if (pos < 0)
return "";
else
return aString.substr(0, pos + 1);
}
tWString cString::GetFilePathW(const tWString &aString) {
if (GetLastStringPosW(aString, _W(".")) < 0)
return aString;
int pos1 = GetLastStringPosW(aString, _W("\\"));
int pos2 = GetLastStringPosW(aString, _W("/"));
int pos = pos1 > pos2 ? pos1 : pos2;
if (pos < 0)
return _W("");
else
return aString.substr(0, pos + 1);
}
//-----------------------------------------------------------------------
tString cString::ReplaceCharTo(tString aString, const tString &asOldChar, const tString &asNewChar) {
if (asNewChar != "") {
for (int i = 0; i < (int)aString.size(); i++) {
if (aString[i] == asOldChar[0])
aString.setChar(asNewChar[0], i);
}
return aString;
} else {
tString sNewString;
for (int i = 0; i < (int)aString.size(); i++) {
if (aString[i] != asOldChar[0])
sNewString += aString[i];
}
return sNewString;
}
}
tWString cString::ReplaceCharToW(tWString aString, const tWString &asOldChar, const tWString &asNewChar) {
if (asNewChar != _W("")) {
for (int i = 0; i < (int)aString.size(); i++) {
if (aString[i] == asOldChar[0])
aString.setChar(asNewChar[0], i);
}
return aString;
} else {
tWString sNewString;
for (int i = 0; i < (int)aString.size(); i++) {
if (aString[i] != asOldChar[0])
sNewString += aString[i];
}
return sNewString;
}
}
//-----------------------------------------------------------------------
tString cString::ReplaceStringTo(const tString &aString, const tString &asOldString, const tString &asNewString) {
tString sNewString = "";
for (size_t i = 0; i < aString.size(); i++) {
bool bFound = true;
// Search for old string
if (aString.size() >= i + asOldString.size()) {
for (size_t j = 0; j < asOldString.size(); ++j) {
if (aString[i + j] != asOldString[j]) {
bFound = false;
break;
}
}
} else {
bFound = false;
}
// Insert new string
if (bFound) {
sNewString += asNewString;
i += asOldString.size() - 1;
}
// Just add the character
else {
sNewString += aString[i];
}
}
return sNewString;
}
//-----------------------------------------------------------------------
// gets the last char in the string
tString cString::GetLastChar(const tString &aString) {
if (aString.size() == 0)
return "";
return aString.substr(aString.size() - 1);
}
tWString cString::GetLastCharW(const tWString &aString) {
if (aString.size() == 0)
return _W("");
return aString.substr(aString.size() - 1);
}
//-----------------------------------------------------------------------
tString cString::ToString(const char *asString, const tString &asDefault) {
if (asString == NULL)
return asDefault;
return asString;
}
//-----------------------------------------------------------------------
int cString::ToInt(const char *asString, int alDefault) {
if (asString == NULL)
return alDefault;
return atoi(asString);
}
//-----------------------------------------------------------------------
float cString::ToFloat(const char *asString, float afDefault) {
if (asString == NULL)
return afDefault;
return (float)atof(asString);
}
//-----------------------------------------------------------------------
bool cString::ToBool(const char *asString, bool abDefault) {
if (asString == NULL)
return abDefault;
tString asTempString = ToLowerCase(asString);
return asTempString == "true" ? true : false;
}
//-----------------------------------------------------------------------
cColor cString::ToColor(const char *asString, const cColor &aDefault) {
if (asString == NULL)
return aDefault;
tFloatVec vValues;
GetFloatVec(asString, vValues, NULL);
if (vValues.size() != 4)
return aDefault;
return cColor(vValues[0], vValues[1], vValues[2], vValues[3]);
}
//-----------------------------------------------------------------------
cVector2f cString::ToVector2f(const char *asString, const cVector2f &avDefault) {
if (asString == NULL)
return avDefault;
tFloatVec vValues;
GetFloatVec(asString, vValues, NULL);
if (vValues.size() != 2)
return avDefault;
return cVector2f(vValues[0], vValues[1]);
}
//-----------------------------------------------------------------------
cVector3f cString::ToVector3f(const char *asString, const cVector3f &avDefault) {
if (asString == NULL)
return avDefault;
tFloatVec vValues;
GetFloatVec(asString, vValues, NULL);
if (vValues.size() != 3)
return avDefault;
return cVector3f(vValues[0], vValues[1], vValues[2]);
}
//-----------------------------------------------------------------------
cVector2l cString::ToVector2l(const char *asString, const cVector2l &avDefault) {
if (asString == NULL)
return avDefault;
tIntVec vValues;
GetIntVec(asString, vValues, NULL);
if (vValues.size() != 2)
return avDefault;
return cVector2l(vValues[0], vValues[1]);
}
//-----------------------------------------------------------------------
cVector3l cString::ToVector3l(const char *asString, const cVector3l &avDefault) {
if (asString == NULL)
return avDefault;
tIntVec vValues;
GetIntVec(asString, vValues, NULL);
if (vValues.size() != 3)
return avDefault;
return cVector3l(vValues[0], vValues[1], vValues[2]);
}
//-----------------------------------------------------------------------
cMatrixf cString::ToMatrixf(const char *asString, const cMatrixf &a_mtxDefault) {
if (asString == NULL)
return a_mtxDefault;
tFloatVec vValues;
GetFloatVec(asString, vValues, NULL);
if (vValues.size() != 16)
return a_mtxDefault;
return cMatrixf(vValues[0], vValues[1], vValues[2], vValues[3],
vValues[4], vValues[5], vValues[6], vValues[7],
vValues[8], vValues[9], vValues[10], vValues[11],
vValues[12], vValues[13], vValues[14], vValues[15]);
}
//-----------------------------------------------------------------------
tIntVec &cString::GetIntVec(const tString &asData, tIntVec &avVec, tString *apSeparators) {
tStringVec mvStr;
GetStringVec(asData, mvStr, apSeparators);
for (int i = 0; i < (int)mvStr.size(); i++) {
avVec.push_back(ToInt(mvStr[i].c_str(), 0));
}
return avVec;
}
//-----------------------------------------------------------------------
tUIntVec &cString::GetUIntVec(const tString &asData, tUIntVec &avVec, tString *apSeparators) {
tStringVec mvStr;
GetStringVec(asData, mvStr, apSeparators);
for (int i = 0; i < (int)mvStr.size(); i++) {
avVec.push_back(ToInt(mvStr[i].c_str(), 0));
}
return avVec;
}
//-----------------------------------------------------------------------
tFloatVec &cString::GetFloatVec(const tString &asData, tFloatVec &avVec, tString *apSeparators) {
tStringVec mvStr;
GetStringVec(asData, mvStr, apSeparators);
for (int i = 0; i < (int)mvStr.size(); i++) {
avVec.push_back(ToFloat(mvStr[i].c_str(), 0));
}
return avVec;
}
//-----------------------------------------------------------------------
tString cString::ToString(int alX) {
char buff[256];
snprintf(buff, 256, "%d", alX);
return buff;
}
tString cString::ToString(float afX) {
char buff[256];
snprintf(buff, 256, "%f", afX);
return buff;
}
//-----------------------------------------------------------------------
tWString cString::ToStringW(int alX) {
return Common::U32String::format("%d", alX);
}
tWString cString::ToStringW(float afX) {
return Common::U32String::format("%f", afX);
}
//-----------------------------------------------------------------------
tStringVec &cString::GetStringVec(const tString &asData, tStringVec &avVec, tString *apSeparators) {
tString str = "";
bool start = false;
tString c = "";
for (int i = 0; i < (int)asData.size(); i++) {
c = asData.substr(i, 1);
bool bNewWord = false;
// Check if the current char is a separator
if (apSeparators) {
for (size_t j = 0; j < apSeparators->size(); j++) {
if ((*apSeparators)[j] == c[0]) {
bNewWord = true;
break;
}
}
} else {
if (c[0] == ' ' || c[0] == '\n' || c[0] == '\t' || c[0] == ',') {
bNewWord = true;
}
}
if (bNewWord) {
if (start) {
start = false;
avVec.push_back(str);
str = "";
}
} else {
start = true;
str += c;
if (i == (int)asData.size() - 1)
avVec.push_back(str);
}
}
return avVec;
}
//-----------------------------------------------------------------------
/// Helper
// returns last char in a string
int cString::GetLastStringPos(const tString &aString, const tString &aChar) {
int pos = -1;
for (int i = 0; i < (int)aString.size(); i++) {
if (aString.substr(i, aChar.size()) == aChar)
pos = i;
}
return pos;
}
/// Helper
// returns last char in a string
int cString::GetLastStringPosW(const tWString &aString, const tWString &aChar) {
int pos = -1;
for (int i = 0; i < (int)aString.size(); i++) {
if (aString.substr(i, aChar.size()) == aChar)
pos = i;
}
return pos;
}
//-----------------------------------------------------------------------
void cString::UIntStringToArray(unsigned int *apArray, const char *apString, int alSize) {
char vTempChar[20];
int lTempCharCount = 0;
int lArrayCount = 0;
int lStringCount = 0;
while (lArrayCount < alSize) {
char c = apString[lStringCount];
// if a space is found, convert the previous characters to a float.
if (c == ' ' || c == 0) {
if (lTempCharCount > 0) {
vTempChar[lTempCharCount] = 0;
apArray[lArrayCount] = (unsigned int)atoi(vTempChar);
lTempCharCount = 0;
lArrayCount++;
}
}
// If character is not a space, add to temp char.
else {
vTempChar[lTempCharCount] = c;
lTempCharCount++;
}
lStringCount++;
}
}
//-----------------------------------------------------------------------
void cString::FloatStringToArray(float *apArray, const char *apString, int alSize) {
char vTempChar[20];
int lTempCharCount = 0;
int lArrayCount = 0;
int lStringCount = 0;
while (lArrayCount < alSize) {
char c = apString[lStringCount];
// if a space is found, convert the previous characters to a float.
if (c == ' ' || c == 0) {
if (lTempCharCount > 0) {
vTempChar[lTempCharCount] = 0;
apArray[lArrayCount] = (float)atof(vTempChar);
lTempCharCount = 0;
lArrayCount++;
}
}
// If character is not a space, add to temp char.
else {
vTempChar[lTempCharCount] = apString[lStringCount];
lTempCharCount++;
}
lStringCount++;
}
}
//-----------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,206 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_STRING_H
#define HPL_STRING_H
#include "hpl1/engine/system/SystemTypes.h"
#include "hpl1/engine/graphics/GraphicsTypes.h"
#include "hpl1/engine/math/MathTypes.h"
namespace hpl {
class cString {
public:
/**
* Converts ascii to unicode
*/
static tWString To16Char(const tString &asString);
/**
* Converts unicode to ascii
*/
static tString To8Char(const tWString &awsString);
/**
* Gets a 16 bit string from an string of numbers
*/
static tWString Get16BitFromArray(const tString &asArray);
/**
* Get the sub string
* \param asString The string to get the sub from. The method error check so the params are correct.
* \param alStart The character to start at.
* \param alCount The number of character to copy to the sub. -1 = all til end.
* \return
*/
static tString Sub(const tString &asString, int alStart, int alCount = -1);
static tWString SubW(const tWString &asString, int alStart, int alCount = -1);
/**
* Get the file extension of a string
* \param aString extension (for example ".exe"). If none "" is returned.
* \return
*/
static tString GetFileExt(const tString &aString);
static tWString GetFileExtW(const tWString &aString);
/**
* Sets the file extension. "" removes extension, for example "test.exe" -> "test"
* \param aString New string
* \param aExt Extension, both ".exe" and "exe" works
* \return
*/
static tString SetFileExt(tString aString, tString aExt);
static tWString SetFileExtW(tWString aString, tWString aExt);
/**
* Gets the file filename in for example: "/files/test/this.txt"
* \param aString The Filename
* \return
*/
static tString GetFileName(const tString &aString);
static tWString GetFileNameW(const tWString &aString);
/**
* Removes the filename from a path
* \param aString
* \return
*/
static tString GetFilePath(const tString &aString);
static tWString GetFilePathW(const tWString &aString);
/**
* Sets the path for a file.
* \param aString
* \param aPath New path
* \return
*/
static tString SetFilePath(const tString &aString, tString aPath);
static tWString SetFilePathW(tWString aString, tWString aPath);
/**
* Converts a string to lower case.
* \param aString
* \return
*/
static tString ToLowerCase(tString aString);
static tWString ToLowerCaseW(tWString aString);
/**
*
* \param aString The string to do the replacement on
* \param asOldChar The char to replace (one character only!)
* \param asNewChar The char to replace with (one character only!)
* \return
*/
static tString ReplaceCharTo(tString aString, const tString &asOldChar, const tString &asNewChar);
static tWString ReplaceCharToW(tWString aString, const tWString &asOldChar, const tWString &asNewChar);
/**
*
* \param aString The string to do the replacement on
* \param asOldString The char to replace
* \param asNewString The char to replace with
* \return
*/
static tString ReplaceStringTo(const tString &aString, const tString &asOldString, const tString &asNewString);
static tString ToString(const char *asString, const tString &asDefault);
static int ToInt(const char *asString, int alDefault);
static bool ToBool(const char *asString, bool abDefault);
static float ToFloat(const char *asString, float afDefault);
static cColor ToColor(const char *asString, const cColor &aDefault);
static cVector2f ToVector2f(const char *asString, const cVector2f &avDefault);
static cVector3f ToVector3f(const char *asString, const cVector3f &avDefault);
static cVector2l ToVector2l(const char *asString, const cVector2l &avDefault);
static cVector3l ToVector3l(const char *asString, const cVector3l &avDefault);
static cMatrixf ToMatrixf(const char *asString, const cMatrixf &a_mtxDefault);
static tString ToString(int alX);
static tString ToString(float afX);
static tWString ToStringW(int alX);
static tWString ToStringW(float afX);
/**
* Get a vector of ints from a string such as "1, 2, 3".
* Valid separators are ' ', '\n', '\t' and ','
* \param &asData The string
* \param avVec a vector the values will be appended to.
* \param apSeparators a pointer to a string with chars to override the default separators
*/
static tIntVec &GetIntVec(const tString &asData, tIntVec &avVec, tString *apSeparators = NULL);
/**
* Get a vector of ints from a string such as "1, 2, 3".
* Valid separators are ' ', '\n', '\t' and ','
* \param &asData The string
* \param avVec a vector the values will be appended to.
* \param apSeparators a pointer to a string with chars to override the default separators
*/
static tUIntVec &GetUIntVec(const tString &asData, tUIntVec &avVec, tString *apSeparators = NULL);
/**
* Get a vector of floats from a string such as "1, 2, 3".
* Valid separators are ' ', '\n', '\t' and ','
* \param &asData The string
* \param avVec a vector the values will be appended to.
* \param apSeparators a pointer to a string with chars to override the default separators
*/
static tFloatVec &GetFloatVec(const tString &asData, tFloatVec &avVec, tString *apSeparators = NULL);
/**
* Get a vector of strings from a string such as "one, two, three".
* Valid separators are ' ', '\n', '\t' and ','
* \param &asData
* \param avVec
* \param apSeparators a pointer to a string with chars to override the default separators
*/
static tStringVec &GetStringVec(const tString &asData, tStringVec &avVec, tString *apSeparators = NULL);
/**
* Gets the last character of the string.
* \param aString
* \return
*/
static tString GetLastChar(const tString &aString);
static tWString GetLastCharW(const tWString &aString);
/**
* Get the last pos where aChar is found.
* \param aString
* \param aChar
* \return >=0 if string is found else -1
*/
static int GetLastStringPos(const tString &aString, const tString &aChar);
static int GetLastStringPosW(const tWString &aString, const tWString &aChar);
static void UIntStringToArray(unsigned int *apArray, const char *apString, int alSize);
static void FloatStringToArray(float *apArray, const char *apString, int alSize);
private:
};
} // namespace hpl
#endif // HPL_STRING_H

View File

@@ -0,0 +1,73 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/system/System.h"
#include "hpl1/engine/system/LogicTimer.h"
#include "hpl1/engine/system/String.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cSystem::cSystem(LowLevelSystem *apLowLevelSystem) {
mpLowLevelSystem = apLowLevelSystem;
}
//-----------------------------------------------------------------------
cSystem::~cSystem() {
Log("Exiting System Module\n");
Log("--------------------------------------------------------\n");
Log("--------------------------------------------------------\n\n");
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cLogicTimer *cSystem::CreateLogicTimer(unsigned int alUpdatesPerSec) {
return hplNew(cLogicTimer, (alUpdatesPerSec, mpLowLevelSystem));
}
//-----------------------------------------------------------------------
LowLevelSystem *cSystem::GetLowLevel() {
return mpLowLevelSystem;
}
//-----------------------------------------------------------------------
} // namespace hpl

View File

@@ -0,0 +1,56 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_SYSTEM_H
#define HPL_SYSTEM_H
namespace hpl {
class LowLevelSystem;
class cLogicTimer;
class cSystem {
public:
cSystem(LowLevelSystem *apLowLevelSystem);
~cSystem();
LowLevelSystem *GetLowLevel();
/**
* Creates a logic timer.
* \param alUpdatesPerSec Frequency of the timer.
* \return
*/
cLogicTimer *CreateLogicTimer(unsigned int alUpdatesPerSec);
private:
LowLevelSystem *mpLowLevelSystem;
};
} // namespace hpl
#endif // HPL_SYSTEM_H

View File

@@ -0,0 +1,522 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_SYSTEM_TYPES_H
#define HPL_SYSTEM_TYPES_H
#include "common/array.h"
#include "common/list.h"
#include "common/str.h"
#include "hpl1/algorithms.h"
#include "hpl1/engine/system/Container.h"
#include "hpl1/std/set.h"
namespace hpl {
//////////////////////////////////////////////////
///////// TYPES //////////////////////////////////
//////////////////////////////////////////////////
#define eFlagBit_None (0x00000000)
#define eFlagBit_All (0xFFFFFFFF)
#define eFlagBit_0 (0x00000001)
#define eFlagBit_1 (0x00000002)
#define eFlagBit_2 (0x00000004)
#define eFlagBit_3 (0x00000008)
#define eFlagBit_4 (0x00000010)
#define eFlagBit_5 (0x00000020)
#define eFlagBit_6 (0x00000040)
#define eFlagBit_7 (0x00000080)
#define eFlagBit_8 (0x00000100)
#define eFlagBit_9 (0x00000200)
#define eFlagBit_10 (0x00000400)
#define eFlagBit_11 (0x00000800)
#define eFlagBit_12 (0x00001000)
#define eFlagBit_13 (0x00002000)
#define eFlagBit_14 (0x00004000)
#define eFlagBit_15 (0x00008000)
#define _W(t) Common::U32String(t)
//--------------------------------------------------------
enum eSystemPath {
eSystemPath_Personal,
eSystemPath_LastEnum
};
//--------------------------------------------------------
typedef unsigned int tFlag;
typedef Common::String tString;
typedef Common::List<tString> tStringList;
typedef tStringList::iterator tStringListIt;
typedef Common::Array<tString> tStringVec;
typedef tStringVec::iterator tStringVecIt;
typedef Hpl1::Std::set<tString> tStringSet;
typedef tStringSet::iterator tStringSetIt;
//--------------------------------------------------------
typedef Common::U32String tWString;
typedef Common::List<tWString> tWStringList;
typedef tWStringList::iterator tWStringListIt;
typedef Common::Array<tWString> tWStringVec;
typedef tWStringVec::iterator tWStringVecIt;
typedef Hpl1::Std::set<tWString> tWStringSet;
typedef tWStringSet::iterator tWStringSetIt;
//--------------------------------------------------------
typedef Common::Array<unsigned char> tByteVec;
typedef tByteVec::iterator tByteVecIt;
typedef Common::Array<unsigned int> tUIntVec;
typedef tUIntVec::iterator tUIntVecIt;
typedef Common::Array<int> tIntVec;
typedef tIntVec::iterator tIntVecIt;
typedef Common::Array<int> tIntList;
typedef tIntVec::iterator tIntListIt;
typedef Common::Array<float> tFloatVec;
typedef tFloatVec::iterator tFloatVecIt;
typedef Common::Array<float *> tFloatPtrVec;
typedef tFloatPtrVec::iterator tFloatPtrVecIt;
typedef Common::List<float *> tFloatPtrList;
typedef tFloatPtrList::iterator tFloatPtrListIt;
typedef Common::List<unsigned int> tUIntList;
typedef tUIntList::iterator tUIntListIt;
typedef enum {
eMsgBoxType_Info,
eMsgBoxType_Error,
eMsgBoxType_Warning,
eMsgBoxType_Default
} eMsgBoxType;
//////////////////////////////////////////////////
///////// DEFINES ///////////////////////////////
//////////////////////////////////////////////////
//--------------------------------------------------------
#define STLCallInAll(ContType, aCont, aFunc) \
{ \
##ContType## ::iterator it = ##aCont##.begin(); \
for (; it != ##aCont##.end(); ++it) \
(*it)->##aFunc##; \
}
//--------------------------------------------------------
//////////////////////////////////////////////////
///////// CLASS //////////////////////////////
//////////////////////////////////////////////////
//--------------------------------------------------------
class cDate {
public:
int seconds;
int minutes;
int hours;
int month_day;
int month;
int year;
int week_day;
int year_day;
tString ToString() {
char buff[256];
snprintf(buff, 256, "%d/%d-%d %d:%d:%d", month_day, month, 1900 + year, hours, minutes, seconds);
return buff;
}
bool operator==(const cDate &aDate) const {
if (seconds == aDate.seconds &&
minutes == aDate.minutes &&
hours == aDate.hours &&
month_day == aDate.month_day &&
month == aDate.month &&
year == aDate.year) {
return true;
}
return false;
}
bool operator!=(const cDate &aDate) const {
return !(*this == aDate);
}
bool operator>(const cDate &aDate) const {
if (year > aDate.year)
return true;
else if (year < aDate.year)
return false;
if (month > aDate.month)
return true;
else if (month < aDate.month)
return false;
if (month_day > aDate.month_day)
return true;
else if (month_day < aDate.month_day)
return false;
if (hours > aDate.hours)
return true;
else if (hours < aDate.hours)
return false;
if (minutes > aDate.minutes)
return true;
else if (minutes < aDate.minutes)
return false;
if (seconds > aDate.seconds)
return true;
else if (seconds < aDate.seconds)
return false;
return false;
}
bool operator<(const cDate &aDate) const {
if (year < aDate.year)
return true;
else if (year > aDate.year)
return false;
if (month < aDate.month)
return true;
else if (month > aDate.month)
return false;
if (month_day < aDate.month_day)
return true;
else if (month_day > aDate.month_day)
return false;
if (hours < aDate.hours)
return true;
else if (hours > aDate.hours)
return false;
if (minutes < aDate.minutes)
return true;
else if (minutes > aDate.minutes)
return false;
if (seconds < aDate.seconds)
return true;
else if (seconds > aDate.seconds)
return false;
return false;
}
};
//--------------------------------------------------------
template<class T>
class cMemoryPool {
public:
//---------------------------------
cMemoryPool(size_t alSize, T *(*apCreateFunc)()) {
Hpl1::resizeAndFill(mvData, alSize, nullptr);
mlCurrentData = 0;
mpCreateFunc = apCreateFunc;
for (size_t i = 0; i < mvData.size(); ++i) {
if (mpCreateFunc)
mvData[i] = mpCreateFunc();
else
mvData[i] = hplNew(T, ());
}
}
//---------------------------------
~cMemoryPool() {
for (size_t i = 0; i < mvData.size(); ++i)
hplDelete(mvData[i]);
}
//---------------------------------
T *Create() {
T *pData = mvData[mlCurrentData];
if (mlCurrentData == mvData.size() - 1) {
size_t lNewSize = mvData.size() * 2;
size_t lStart = mvData.size();
mvData.resize(lNewSize);
for (size_t i = lStart; i < mvData.size(); ++i) {
if (mpCreateFunc)
mvData[i] = mpCreateFunc();
else
mvData[i] = hplNew(T, ());
}
++mlCurrentData;
} else {
++mlCurrentData;
}
return pData;
}
//---------------------------------
void Release(T *apData) {
if (mlCurrentData == 0)
return;
--mlCurrentData;
mvData[mlCurrentData] = apData;
}
//---------------------------------
void ClearUnused() {
for (size_t i = mlCurrentData + 1; i < mvData.size(); ++i) {
hplDelete(mvData[i]);
}
mvData.resize(mlCurrentData + 1);
}
//---------------------------------
private:
Common::Array<T *> mvData;
size_t mlCurrentData;
T *(*mpCreateFunc)();
};
//----------------------------------------------------------
//////////////////////////////////////////////////
///////// TEMPLATES //////////////////////////////
//////////////////////////////////////////////////
//--------------------------------------------------------
template<class CONT, class T>
void STLFindAndRemove(CONT &aCont, T *pObject) {
typename CONT::iterator it = aCont.begin();
for (; it != aCont.end(); it++) {
if (*it == pObject) {
aCont.erase(it);
}
}
}
//--------------------------------------------------------
template<class CONT, class T>
void STLFindAndDelete(CONT &aCont, T *pObject) {
typename CONT::iterator it = aCont.begin();
for (; it != aCont.end(); it++) {
if (*it == pObject) {
aCont.erase(it);
break;
}
}
hplDelete(pObject);
}
//--------------------------------------------------------
template<class CONT>
void *STLFindByName(CONT &aCont, const tString &asName) {
typename CONT::iterator it = aCont.begin();
for (; it != aCont.end(); it++) {
if ((*it)->GetName() == asName) {
return *it;
}
}
return NULL;
}
//--------------------------------------------------------
template<class T>
void STLDeleteAll(T &aCont) {
typename T::iterator it = aCont.begin();
for (; it != aCont.end(); it++) {
hplDelete(*it);
}
aCont.clear();
}
//--------------------------------------------------------
template<class T>
void STLMapDeleteAll(T &aCont) {
typename T::iterator it = aCont.begin();
for (; it != aCont.end(); it++) {
hplDelete(it->second);
}
aCont.clear();
}
//--------------------------------------------------------
template<class T, class CONT, class IT>
class cSTLIterator : public iContainerIterator {
public:
///////////////////////////
cSTLIterator(CONT *apCont) {
mpCont = apCont;
mIt = mpCont->begin();
}
///////////////////////////
bool HasNext() {
return mIt != mpCont->end();
}
void *NextPtr() {
if (mIt == mpCont->end())
return NULL;
else {
T &temp = const_cast<T &>(*mIt);
mIt++;
return &temp;
}
}
///////////////////////////
T Next() {
if (mIt == mpCont->end())
return NULL;
else {
T &temp = const_cast<T &>(*mIt);
mIt++;
return temp;
}
}
///////////////////////////
T PeekNext() {
if (mIt == mpCont->end())
return NULL;
else {
return *mIt;
}
}
///////////////////////////
private:
IT mIt;
CONT *mpCont;
};
//--------------------------------------------------------
template<class T, class CONT, class IT>
class cSTLMapIterator : public iContainerIterator {
public:
///////////////////////////
cSTLMapIterator(CONT *apCont) {
mpCont = apCont;
mIt = mpCont->begin();
}
///////////////////////////
bool HasNext() {
return mIt != mpCont->end();
}
void *NextPtr() {
if (mIt == mpCont->end())
return NULL;
else {
T &temp = mIt->second;
mIt++;
return &temp;
}
}
///////////////////////////
T Next() {
if (mIt == mpCont->end())
return NULL;
else {
T temp = mIt->second;
mIt++;
return temp;
}
}
///////////////////////////
T PeekNext() {
if (mIt == mpCont->end())
return NULL;
else {
return mIt->second;
}
}
///////////////////////////
private:
IT mIt;
CONT *mpCont;
};
} // namespace hpl
#endif // HPL_SYSTEM_TYPES_H

View File

@@ -0,0 +1,409 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "hpl1/engine/impl/SqScript.h"
#include "hpl1/engine/libraries/angelscript/add-ons/scriptarray.h"
#include "hpl1/engine/libraries/angelscript/add-ons/scriptstdstring.h"
#include "hpl1/engine/libraries/angelscript/angelscript.h"
#include "hpl1/engine/system/String.h"
#include "hpl1/debug.h"
#include "hpl1/hpl1.h"
#include "common/system.h"
namespace hpl {
static void scriptEngineLog(const asSMessageInfo *msg) {
switch (msg->type) {
case asMSGTYPE_ERROR:
Hpl1::logError(Hpl1::kDebugScripts, "%s (%d, %d) : %s\n", msg->section, msg->row, msg->col, msg->message);
break;
case asMSGTYPE_WARNING:
Hpl1::logWarning(Hpl1::kDebugScripts, "%s (%d, %d) : %s\n", msg->section, msg->row, msg->col, msg->message);
break;
case asMSGTYPE_INFORMATION:
Hpl1::logInfo(Hpl1::kDebugScripts, "%s (%d, %d) : %s\n", msg->section, msg->row, msg->col, msg->message);
}
}
LowLevelSystem::LowLevelSystem() {
_scriptEngine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
RegisterScriptArray(_scriptEngine, true);
_scriptEngine->SetMessageCallback(asFunctionPtr(scriptEngineLog), nullptr, asCALL_CDECL);
RegisterStdString(_scriptEngine);
_handleCount = 0;
}
LowLevelSystem::~LowLevelSystem() {
/*Release all runnings contexts */
cleanupRegisteredString();
_scriptEngine->Release();
// perhaps not the best thing to skip :)
// if(gpLogWriter) hplDelete(gpLogWriter);
// gpLogWriter = NULL;
}
static void commonLog(int level, const char *fmt, va_list args) {
char buffer[256];
vsnprintf(buffer, 256, fmt, args);
debugN(level, "%s", buffer);
}
void Error(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
commonLog(Hpl1::kDebugLevelError, fmt, args);
va_end(args);
}
void Warning(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
commonLog(Hpl1::kDebugLevelWarning, fmt, args);
va_end(args);
}
void Log(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
commonLog(Hpl1::kDebugLevelLog, fmt, args);
va_end(args);
}
static bool gbUpdateLogIsActive;
void SetUpdateLogActive(bool abX) {
gbUpdateLogIsActive = abX;
}
void LogUpdate(const char *fmt, ...) {
#if 0
if (!gbUpdateLogIsActive)
return;
char text[2048];
va_list ap;
if (fmt == NULL)
return;
va_start(ap, fmt);
vsnprintf(text, 2048, fmt, ap);
va_end(ap);
tString sMess = "";
sMess += text;
gUpdateLogWriter.Write(sMess);
#endif
}
//-----------------------------------------------------------------------
void CopyTextToClipboard(const tWString &text) {
g_system->setTextInClipboard(text);
}
tWString LoadTextFromClipboard() {
Common::U32String text = g_system->getTextFromClipboard();
return text;
}
//-----------------------------------------------------------------------
void CreateMessageBoxW(eMsgBoxType eType, const wchar_t *caption, const wchar_t *fmt, va_list ap) {
}
void CreateMessageBoxW(eMsgBoxType eType, const wchar_t *caption, const wchar_t *fmt, ...) {
}
void CreateMessageBoxW(const wchar_t *caption, const wchar_t *fmt, ...) {
}
//-----------------------------------------------------------------------
/*static cDate DateFromGMTIme(struct tm *apClock) {
cDate date;
date.seconds = apClock->tm_sec;
date.minutes = apClock->tm_min;
date.hours = apClock->tm_hour;
date.month_day = apClock->tm_mday;
date.month = apClock->tm_mon;
date.year = 1900 + apClock->tm_year;
date.week_day = apClock->tm_wday;
date.year_day = apClock->tm_yday;
return date;
}*/
//-----------------------------------------------------------------------
void OpenBrowserWindow(const tWString &URL) {
g_system->openUrl(URL);
}
//-----------------------------------------------------------------------
tWString GetSystemSpecialPath(eSystemPath aPathType) {
#if 0
#if defined(WIN32)
int type;
switch(aPathType)
{
case eSystemPath_Personal: type = CSIDL_PERSONAL;
break;
default: return _W("");
}
TCHAR sPath[1024];
if(SUCCEEDED(SHGetFolderPath(NULL,
type | CSIDL_FLAG_CREATE,
NULL,0,sPath)))
{
return tWString(sPath);
}
else
{
return _W("");
}
#else
switch (aPathType)
{
case eSystemPath_Personal: {
const char *home = getenv("HOME");
return cString::To16Char(tString(home));
}
default:
return _W("");
}
#endif
#endif
return Common::U32String("");
}
//-----------------------------------------------------------------------
bool FileExists(const tWString &fileName) {
#if 0
#ifdef WIN32
FILE *f = _wfopen(fileName.c_str(),_W("r"));
#else
FILE *f = fopen(cString::To8Char(fileName).c_str(),"r");
#endif
if(f==NULL)
{
return false;
}
fclose(f);
return true;
#endif
return false;
}
//-----------------------------------------------------------------------
void RemoveFile(const tWString &filePath) {
#if 0
#ifdef WIN32
_wremove(filePath.c_str());
#else
remove(cString::To8Char(filePath).c_str());
#endif
#endif
}
//-----------------------------------------------------------------------
bool CloneFile(const tWString &srcFileName, const tWString &destFileName,
bool abFailIfExists) {
#if 0
#ifdef WIN32
return CopyFile(srcFileName.c_str(),destFileName.c_str(),abFailIfExists)==TRUE;
#else
if (abFailIfExists && FileExists(destFileName)) {
return true;
}
std::ifstream IN (cString::To8Char(srcFileName).c_str(), std::ios::binary);
std::ofstream OUT (cString::To8Char(destFileName).c_str(), std::ios::binary);
OUT << IN.rdbuf();
OUT.flush();
return true;
#endif
#endif
return false;
}
//-----------------------------------------------------------------------
bool CreateFolder(const tWString &path) {
#if 0
#ifdef WIN32
return CreateDirectory(path.c_str(),NULL)==TRUE;
#else
return mkdir(cString::To8Char(path).c_str(),0755)==0;
#endif
#endif
return false;
}
bool FolderExists(const tWString &path) {
#if 0
#ifdef WIN32
return GetFileAttributes(path.c_str())==FILE_ATTRIBUTE_DIRECTORY;
#else
struct stat statbuf;
return (stat(cString::To8Char(path).c_str(), &statbuf) != -1);
#endif
#endif
return false;
}
bool IsFileLink(const tWString &path) {
#if 0
// Symbolic Links Not Supported under Windows
#ifndef WIN32
struct stat statbuf;
if (lstat(cString::To8Char(path).c_str(), &statbuf) == 0) {
return statbuf.st_mode == S_IFLNK;
} else {
return false;
}
#else
return false;
#endif
#endif
return false;
}
bool LinkFile(const tWString &pointsTo, const tWString &link) {
#if 0
// Symbolic Links Not Supported under Windows
#ifndef WIN32
return (symlink(cString::To8Char(pointsTo).c_str(), cString::To8Char(link).c_str()) == 0);
#else
return false;
#endif
#endif
return false;
}
bool RenameFile(const tWString &from, const tWString &to) {
#if 0
#ifdef WIN32
return false;
#else
return (rename(cString::To8Char(from).c_str(), cString::To8Char(to).c_str()) == 0);
#endif
#endif
return false;
}
//-----------------------------------------------------------------------
cDate FileModifiedDate(const tWString &filePath) {
#if 0
struct tm* pClock;
#ifdef WIN32
struct _stat attrib;
_wstat(filePath.c_str(), &attrib);
#else
struct stat attrib;
stat(cString::To8Char(filePath).c_str(), &attrib);
#endif
pClock = gmtime(&(attrib.st_mtime)); // Get the last modified time and put it into the time structure
cDate date = DateFromGMTIme(pClock);
return date;
#endif
return {};
}
//-----------------------------------------------------------------------
cDate FileCreationDate(const tWString &filePath) {
#if 0
struct tm* pClock;
#ifdef WIN32
struct _stat attrib;
_wstat(filePath.c_str(), &attrib);
#else
struct stat attrib;
stat(cString::To8Char(filePath).c_str(), &attrib);
#endif
pClock = gmtime(&(attrib.st_ctime)); // Get the last modified time and put it into the time structure
cDate date = DateFromGMTIme(pClock);
return date;
#endif
return {};
}
//-----------------------------------------------------------------------
void SetWindowCaption(const tString &name) {
g_system->setWindowCaption(Common::U32String(name.c_str()));
}
unsigned long GetApplicationTime() {
return g_engine->getTotalPlayTime();
}
unsigned long LowLevelSystem::getTime() {
return g_engine->getTotalPlayTime();
}
cDate LowLevelSystem::getDate() {
TimeDate td;
g_system->getTimeAndDate(td);
return {td.tm_sec, td.tm_min, td.tm_hour, td.tm_mday, td.tm_mon, td.tm_year - 100, td.tm_wday, 0};
}
iScript *LowLevelSystem::createScript(const tString &name) {
return hplNew(cSqScript, (name, _scriptEngine, _handleCount++));
}
bool LowLevelSystem::addScriptFunc(const tString &funcDecl, asGENFUNC_t pFunc, int callConv) {
if (_scriptEngine->RegisterGlobalFunction(funcDecl.c_str(),
asFUNCTION(pFunc), callConv) < 0) {
Hpl1::logError(Hpl1::kDebugScripts, "Couldn't add script function '%s'\n", funcDecl.c_str());
return false;
}
return true;
}
bool LowLevelSystem::addScriptVar(const tString &varDecl, void *pVar) {
if (_scriptEngine->RegisterGlobalProperty(varDecl.c_str(), pVar) < 0) {
Error("Couldn't add var '%s'\n", varDecl.c_str());
return false;
}
return true;
}
void LowLevelSystem::sleep(const unsigned int alMillisecs) {
}
} // namespace hpl

View File

@@ -0,0 +1,146 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#ifndef HPL_LOWLEVELSYSTEM_H
#define HPL_LOWLEVELSYSTEM_H
#include "hpl1/engine/libraries/angelscript/angelscript.h"
#include "hpl1/engine/system/MemoryManager.h"
#include "hpl1/engine/system/SystemTypes.h"
class asIScriptEngine;
namespace hpl {
#ifdef UPDATE_TIMING_ENABLED
#define START_TIMING_EX(x, y) \
LogUpdate("Updating %s in file %s at line %d\n", x, __FILE__, __LINE__); \
unsigned int y##_lTime = GetApplicationTime();
#define START_TIMING(x) \
LogUpdate("Updating %s in file %s at line %d\n", #x, __FILE__, __LINE__); \
unsigned int x##_lTime = GetApplicationTime();
#define STOP_TIMING(x) LogUpdate(" Time spent: %d ms\n", GetApplicationTime() - x##_lTime);
#define START_TIMING_TAB(x) \
LogUpdate("\tUpdating %s in file %s at line %d\n", #x, __FILE__, __LINE__); \
unsigned int x##_lTime = GetApplicationTime();
#define STOP_TIMING_TAB(x) LogUpdate("\t Time spent: %d ms\n", GetApplicationTime() - x##_lTime);
#else
#define START_TIMING_EX(x, y)
#define START_TIMING(x)
#define STOP_TIMING(x)
#define START_TIMING_TAB(x)
#define STOP_TIMING_TAB(x)
#endif
class iScript;
extern void SetLogFile(const tWString &File);
extern void Error(const char *fmt, ...);
extern void Warning(const char *fmt, ...);
extern void Log(const char *fmt, ...);
extern void SetUpdateLogActive(bool abX);
extern void LogUpdate(const char *fmt, ...);
extern void CreateMessageBoxW(const wchar_t *caption, const wchar_t *fmt, ...);
extern void CreateMessageBoxW(eMsgBoxType eType, const wchar_t *caption, const wchar_t *fmt, ...);
extern void OpenBrowserWindow(const tWString &URL);
extern void CopyTextToClipboard(const tWString &text);
extern tWString LoadTextFromClipboard();
extern tWString GetSystemSpecialPath(eSystemPath pathType);
extern bool FileExists(const tWString &fileName);
extern void RemoveFile(const tWString &fileName);
extern bool CloneFile(const tWString &srcFileName, const tWString &destFileName,
bool failIfExists);
extern bool CreateFolder(const tWString &path);
extern bool FolderExists(const tWString &path);
extern bool IsFileLink(const tWString &path);
extern bool LinkFile(const tWString &pointsTo, const tWString &link);
extern bool RenameFile(const tWString &from, const tWString &to);
extern cDate FileModifiedDate(const tWString &filePath);
extern cDate FileCreationDate(const tWString &filePath);
extern void SetWindowCaption(const tString &name);
extern unsigned long GetApplicationTime();
class LowLevelSystem {
public:
LowLevelSystem();
~LowLevelSystem();
/**
* Remark: Usually not finer then 10ms accuracy.
* \return Number of millisecs since start of app.
*/
unsigned long getTime();
/**
* Gets the current date.
*/
cDate getDate();
/**
* Creates a ne script
* \param name name of the script.
* \return
*/
iScript *createScript(const tString &name);
/**
* Add a function to the script vm. Example: "void test(float x)"
* \param funcDecl the declaration.
* \return
*/
bool addScriptFunc(const tString &funcDecl, asGENFUNC_t func, int callConv);
/**
* Add a variable to the script vm. Example: "int MyVar"
* \param varDecl the declartion
* \param *pVar the variable
* \return
*/
bool addScriptVar(const tString &varDecl, void *var);
/**
* Sets the main thread to rest for a number of milliseconds.
* \param alMillisecs
*/
void sleep(const unsigned int millisecs);
private:
asIScriptEngine *_scriptEngine;
int _handleCount;
};
} // namespace hpl
#endif // HPL_LOWLEVELSYSTEM_H