mirror of
https://github.com/electronicarts/CnC_Renegade.git
synced 2026-02-03 23:43:56 -05:00
Initial commit of Command & Conquer Renegade source code.
This commit is contained in:
84
Code/wwlib/CallbackHook.h
Normal file
84
Code/wwlib/CallbackHook.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* FILE
|
||||
* $Archive: /Commando/Code/wwlib/CallbackHook.h $
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Steven Clinard
|
||||
* $Author: Denzil_l $
|
||||
*
|
||||
* VERSION INFO
|
||||
* $Modtime: 7/03/01 4:59p $
|
||||
* $Revision: 1 $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CALLBACKHOOK_H__
|
||||
#define __CALLBACKHOOK_H__
|
||||
|
||||
class CallbackHook
|
||||
{
|
||||
public:
|
||||
CallbackHook()
|
||||
{}
|
||||
|
||||
virtual ~CallbackHook()
|
||||
{}
|
||||
|
||||
virtual bool DoCallback(void)
|
||||
{return false;}
|
||||
|
||||
protected:
|
||||
CallbackHook(const CallbackHook&);
|
||||
const CallbackHook& operator=(const CallbackHook&);
|
||||
};
|
||||
|
||||
|
||||
template<class T> class Callback :
|
||||
public CallbackHook
|
||||
{
|
||||
public:
|
||||
Callback(bool (*callback)(T), T userdata) :
|
||||
mCallback(callback),
|
||||
mUserData(userdata)
|
||||
{}
|
||||
|
||||
virtual ~Callback()
|
||||
{}
|
||||
|
||||
virtual bool DoCallback(void)
|
||||
{
|
||||
if (mCallback)
|
||||
{
|
||||
return mCallback(mUserData);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool (*mCallback)(T);
|
||||
T mUserData;
|
||||
};
|
||||
|
||||
#endif // __CALLBACKHOOK_H__
|
||||
BIN
Code/wwlib/Debug/Except.sbr
Normal file
BIN
Code/wwlib/Debug/Except.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/FastAllocator.sbr
Normal file
BIN
Code/wwlib/Debug/FastAllocator.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/LaunchWeb.sbr
Normal file
BIN
Code/wwlib/Debug/LaunchWeb.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/TARGA.sbr
Normal file
BIN
Code/wwlib/Debug/TARGA.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/WWCOMUtil.sbr
Normal file
BIN
Code/wwlib/Debug/WWCOMUtil.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/_convert.sbr
Normal file
BIN
Code/wwlib/Debug/_convert.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/_mono.sbr
Normal file
BIN
Code/wwlib/Debug/_mono.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/argv.sbr
Normal file
BIN
Code/wwlib/Debug/argv.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/b64pipe.sbr
Normal file
BIN
Code/wwlib/Debug/b64pipe.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/b64straw.sbr
Normal file
BIN
Code/wwlib/Debug/b64straw.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/base64.sbr
Normal file
BIN
Code/wwlib/Debug/base64.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/blit.sbr
Normal file
BIN
Code/wwlib/Debug/blit.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/blowfish.sbr
Normal file
BIN
Code/wwlib/Debug/blowfish.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/buff.sbr
Normal file
BIN
Code/wwlib/Debug/buff.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/bufffile.sbr
Normal file
BIN
Code/wwlib/Debug/bufffile.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/chunkio.sbr
Normal file
BIN
Code/wwlib/Debug/chunkio.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/convert.sbr
Normal file
BIN
Code/wwlib/Debug/convert.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/cpudetect.sbr
Normal file
BIN
Code/wwlib/Debug/cpudetect.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/crc.sbr
Normal file
BIN
Code/wwlib/Debug/crc.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/cstraw.sbr
Normal file
BIN
Code/wwlib/Debug/cstraw.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/data.sbr
Normal file
BIN
Code/wwlib/Debug/data.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/ddraw.sbr
Normal file
BIN
Code/wwlib/Debug/ddraw.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/dsurface.sbr
Normal file
BIN
Code/wwlib/Debug/dsurface.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/ffactory.sbr
Normal file
BIN
Code/wwlib/Debug/ffactory.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/gcd_lcm.sbr
Normal file
BIN
Code/wwlib/Debug/gcd_lcm.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/hash.sbr
Normal file
BIN
Code/wwlib/Debug/hash.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/hsv.sbr
Normal file
BIN
Code/wwlib/Debug/hsv.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/ini.sbr
Normal file
BIN
Code/wwlib/Debug/ini.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/int.sbr
Normal file
BIN
Code/wwlib/Debug/int.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/jshell.sbr
Normal file
BIN
Code/wwlib/Debug/jshell.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/keyboard.sbr
Normal file
BIN
Code/wwlib/Debug/keyboard.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/lcw.sbr
Normal file
BIN
Code/wwlib/Debug/lcw.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/load.sbr
Normal file
BIN
Code/wwlib/Debug/load.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/lzo.sbr
Normal file
BIN
Code/wwlib/Debug/lzo.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/lzo1x_c.sbr
Normal file
BIN
Code/wwlib/Debug/lzo1x_c.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/lzo1x_d.sbr
Normal file
BIN
Code/wwlib/Debug/lzo1x_d.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/md5.sbr
Normal file
BIN
Code/wwlib/Debug/md5.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/mixfile.sbr
Normal file
BIN
Code/wwlib/Debug/mixfile.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/mono.sbr
Normal file
BIN
Code/wwlib/Debug/mono.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/mpmath.sbr
Normal file
BIN
Code/wwlib/Debug/mpmath.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/mpu.sbr
Normal file
BIN
Code/wwlib/Debug/mpu.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/msgloop.sbr
Normal file
BIN
Code/wwlib/Debug/msgloop.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/multilist.sbr
Normal file
BIN
Code/wwlib/Debug/multilist.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/mutex.sbr
Normal file
BIN
Code/wwlib/Debug/mutex.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/nstrdup.sbr
Normal file
BIN
Code/wwlib/Debug/nstrdup.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/palette.sbr
Normal file
BIN
Code/wwlib/Debug/palette.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/pcx.sbr
Normal file
BIN
Code/wwlib/Debug/pcx.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/pipe.sbr
Normal file
BIN
Code/wwlib/Debug/pipe.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/pk.sbr
Normal file
BIN
Code/wwlib/Debug/pk.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/ramfile.sbr
Normal file
BIN
Code/wwlib/Debug/ramfile.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/random.sbr
Normal file
BIN
Code/wwlib/Debug/random.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/rawfile.sbr
Normal file
BIN
Code/wwlib/Debug/rawfile.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/rc4.sbr
Normal file
BIN
Code/wwlib/Debug/rc4.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/rcfile.sbr
Normal file
BIN
Code/wwlib/Debug/rcfile.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/readline.sbr
Normal file
BIN
Code/wwlib/Debug/readline.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/realcrc.sbr
Normal file
BIN
Code/wwlib/Debug/realcrc.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/refcount.sbr
Normal file
BIN
Code/wwlib/Debug/refcount.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/registry.sbr
Normal file
BIN
Code/wwlib/Debug/registry.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/rgb.sbr
Normal file
BIN
Code/wwlib/Debug/rgb.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/rle.sbr
Normal file
BIN
Code/wwlib/Debug/rle.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/rndstrng.sbr
Normal file
BIN
Code/wwlib/Debug/rndstrng.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/sampler.sbr
Normal file
BIN
Code/wwlib/Debug/sampler.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/sha.sbr
Normal file
BIN
Code/wwlib/Debug/sha.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/slnode.sbr
Normal file
BIN
Code/wwlib/Debug/slnode.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/srandom.sbr
Normal file
BIN
Code/wwlib/Debug/srandom.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/stimer.sbr
Normal file
BIN
Code/wwlib/Debug/stimer.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/straw.sbr
Normal file
BIN
Code/wwlib/Debug/straw.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/strtok_r.sbr
Normal file
BIN
Code/wwlib/Debug/strtok_r.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/systimer.sbr
Normal file
BIN
Code/wwlib/Debug/systimer.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/tagblock.sbr
Normal file
BIN
Code/wwlib/Debug/tagblock.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/textfile.sbr
Normal file
BIN
Code/wwlib/Debug/textfile.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/thread.sbr
Normal file
BIN
Code/wwlib/Debug/thread.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/trim.sbr
Normal file
BIN
Code/wwlib/Debug/trim.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/vector.sbr
Normal file
BIN
Code/wwlib/Debug/vector.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/verchk.sbr
Normal file
BIN
Code/wwlib/Debug/verchk.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/widestring.sbr
Normal file
BIN
Code/wwlib/Debug/widestring.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/win.sbr
Normal file
BIN
Code/wwlib/Debug/win.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/wwfile.sbr
Normal file
BIN
Code/wwlib/Debug/wwfile.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/wwfont.sbr
Normal file
BIN
Code/wwlib/Debug/wwfont.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/wwstring.sbr
Normal file
BIN
Code/wwlib/Debug/wwstring.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/xpipe.sbr
Normal file
BIN
Code/wwlib/Debug/xpipe.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/xstraw.sbr
Normal file
BIN
Code/wwlib/Debug/xstraw.sbr
Normal file
Binary file not shown.
BIN
Code/wwlib/Debug/xsurface.sbr
Normal file
BIN
Code/wwlib/Debug/xsurface.sbr
Normal file
Binary file not shown.
1312
Code/wwlib/Except.cpp
Normal file
1312
Code/wwlib/Except.cpp
Normal file
File diff suppressed because it is too large
Load Diff
88
Code/wwlib/Except.h
Normal file
88
Code/wwlib/Except.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/***********************************************************************************************
|
||||
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
|
||||
***********************************************************************************************
|
||||
* *
|
||||
* Project Name : Command & Conquer *
|
||||
* *
|
||||
* $Archive:: /Commando/Code/wwlib/Except.h $*
|
||||
* *
|
||||
* $Author:: Steve_t $*
|
||||
* *
|
||||
* $Modtime:: 2/07/02 12:28p $*
|
||||
* *
|
||||
* $Revision:: 6 $*
|
||||
* *
|
||||
*---------------------------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef EXCEPT_H
|
||||
#define EXCEPT_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#include "win.h"
|
||||
/*
|
||||
** Forward Declarations
|
||||
*/
|
||||
typedef struct _EXCEPTION_POINTERS EXCEPTION_POINTERS;
|
||||
typedef struct _CONTEXT CONTEXT;
|
||||
|
||||
int Exception_Handler(int exception_code, EXCEPTION_POINTERS *e_info);
|
||||
int Stack_Walk(unsigned long *return_addresses, int num_addresses, CONTEXT *context = NULL);
|
||||
bool Lookup_Symbol(void *code_ptr, char *symbol, int &displacement);
|
||||
void Load_Image_Helper(void);
|
||||
void Register_Thread_ID(unsigned long thread_id, char *thread_name, bool main = false);
|
||||
void Unregister_Thread_ID(unsigned long thread_id, char *thread_name);
|
||||
void Register_Application_Exception_Callback(void (*app_callback)(void));
|
||||
void Register_Application_Version_Callback(char *(*app_version_callback)(void));
|
||||
void Set_Exit_On_Exception(bool set);
|
||||
bool Is_Trying_To_Exit(void);
|
||||
unsigned long Get_Main_Thread_ID(void);
|
||||
#if (0)
|
||||
bool Register_Thread_Handle(unsigned long thread_id, HANDLE thread_handle);
|
||||
int Get_Num_Thread(void);
|
||||
HANDLE Get_Thread_Handle(int thread_index);
|
||||
#endif //(0)
|
||||
|
||||
/*
|
||||
** Register dump variables. These are used to allow the game to restart from an arbitrary
|
||||
** position after an exception occurs.
|
||||
*/
|
||||
extern unsigned long ExceptionReturnStack;
|
||||
extern unsigned long ExceptionReturnAddress;
|
||||
extern unsigned long ExceptionReturnFrame;
|
||||
|
||||
|
||||
typedef struct tThreadInfoType {
|
||||
char ThreadName[128];
|
||||
unsigned long ThreadID;
|
||||
HANDLE ThreadHandle;
|
||||
bool Main;
|
||||
} ThreadInfoType;
|
||||
|
||||
|
||||
|
||||
#endif //_MSC_VER
|
||||
|
||||
#endif //EXCEPT_H
|
||||
41
Code/wwlib/FastAllocator.cpp
Normal file
41
Code/wwlib/FastAllocator.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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 "FastAllocator.h"
|
||||
|
||||
static FastAllocatorGeneral* generalAllocator; //This general allocator will do all allocations for us.
|
||||
|
||||
FastAllocatorGeneral* FastAllocatorGeneral::Get_Allocator()
|
||||
{
|
||||
if (!generalAllocator) {
|
||||
generalAllocator=reinterpret_cast<FastAllocatorGeneral*>(::malloc(sizeof(FastAllocatorGeneral)));
|
||||
|
||||
new (generalAllocator) FastAllocatorGeneral();
|
||||
}
|
||||
return generalAllocator;
|
||||
}
|
||||
|
||||
FastAllocatorGeneral::FastAllocatorGeneral() : MemoryLeakLogEnabled(false), AllocatedWithMalloc(0), AllocatedWithMallocCount(0), ActualMemoryUsage(0)
|
||||
{
|
||||
int alloc_size=ALLOC_STEP;
|
||||
for (int i=0;i<MAX_ALLOC_SIZE/ALLOC_STEP;++i) {
|
||||
allocators[i].Init(alloc_size);
|
||||
alloc_size+=ALLOC_STEP;
|
||||
}
|
||||
}
|
||||
|
||||
735
Code/wwlib/FastAllocator.h
Normal file
735
Code/wwlib/FastAllocator.h
Normal file
@@ -0,0 +1,735 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FastAllocator.h
|
||||
//
|
||||
// Implements simple and fast memory allocators. Includes sample code for
|
||||
// STL and overriding of specific or global new/delete.
|
||||
//
|
||||
// Allocators are very fast and prevent memory fragmentation. They use up
|
||||
// a little more space on average than generic new/malloc free/delete.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef FASTALLOCATOR_H
|
||||
#define FASTALLOCATOR_H
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
//#define MEMORY_OVERWRITE_TEST
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Include files
|
||||
//
|
||||
#include "always.h"
|
||||
#include "wwdebug.h"
|
||||
#include "mutex.h"
|
||||
#include <malloc.h>
|
||||
#include <stddef.h> //size_t & ptrdiff_t definition
|
||||
#include <string.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Forward Declarations
|
||||
//
|
||||
class FastFixedAllocator; //Allocates and deletes items of a fixed size.
|
||||
class FastAllocatorGeneral; //Allocates and deletes items of any size. Can use as a fast replacement for global new/delete.
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StackAllocator
|
||||
//
|
||||
// Introduction:
|
||||
// This templated class allows you to allocate a dynamically sized temporary
|
||||
// block of memory local to a function in a way that causes it to use some
|
||||
// stack space instead of using the (very slow) malloc function. You don't
|
||||
// want to call malloc/new to allocate temporary blocks of memory when speed
|
||||
// is important. This class is only practical if you are allocating arrays of
|
||||
// objects (especially smaller objects). If you have a class whose size is
|
||||
// 40K, you aren't going to be able to put even one of them on the stack.
|
||||
// If you don't need an array but instead just need a single object, then you
|
||||
// can simply create your object on the stack and be done with it. However,
|
||||
// there are some times when you need a temporary array of objects (or just
|
||||
// an array of chars or pointers) but don't know the size beforehand. That's
|
||||
// where this class is useful.
|
||||
//
|
||||
// Parameters:
|
||||
// The class takes three templated parameters: T, nStackCount, bConstruct.
|
||||
// T -- The type of object being allocated. Examples include char,
|
||||
// cRZString, int*, cRZRect*.
|
||||
// nStackCount -- How many items to allocate on the stack before switching
|
||||
// to a heap allocation. Note that if you want to write
|
||||
// portable code, you need to use no more than about 2K
|
||||
// of stack space. So make sure nStackCount*sizeof(T) < 2048.
|
||||
// bConstruct -- This is normally 1, but setting it to 0 is a hint to the
|
||||
// compiler that you are constructing a type that has no
|
||||
// constructor. Testing showed that the VC++ compiler wasn't
|
||||
// completely able to optimize on its own. In particular, it
|
||||
// was smart enough to remove the while loop, but not smart
|
||||
// enough to remore the pTArrayEnd assignment.
|
||||
//
|
||||
// Benchmarks:
|
||||
// Testing one one machine showed that allocating and freeing a block of
|
||||
// 2048 bytes via malloc/free took 8700 and 8400 clock ticks respectively.
|
||||
// Using this stack allocator to do the same thing tooko 450 and 375 clock
|
||||
// ticks respectively.
|
||||
//
|
||||
// Usage and examples:
|
||||
// Since we are using a local allocator and not overloading global or class
|
||||
// operator new, you have to directory call StackAllocator::New instead
|
||||
// of operator new. So instead of saying:
|
||||
// SomeStruct* pStructArray = new SomeStruct[13];
|
||||
// you say:
|
||||
// SomeStruct* pStructArray = stackAllocator.New(13);
|
||||
//
|
||||
// void Example(int nSize){
|
||||
// StackAllocator<char, 512> stackAllocator; //Create an instance
|
||||
// char* pArray = stackAllocator.New(nSize); //Allocate memory, it will auto-freed.
|
||||
// memset(pArray, 0, nSize*sizeof(char)); //Do something with the memory.
|
||||
// }
|
||||
//
|
||||
// void Example(int nSize){
|
||||
// StackAllocator<int*, 512, 0> stackAllocator; //Create an instance. We use the 'construct' hint feature here.
|
||||
// int** pArray = stackAllocator.New(nSize); //Allocate memory.
|
||||
// memset(pArray, 0, nSize*sizeof(int*)); //Do something with the memory.
|
||||
// stackAllocator.Delete(pArray); //In this example, we explicity free the memory.
|
||||
// }
|
||||
//
|
||||
// void Example(int nSize){
|
||||
// StackAllocator<cRZRect, 200> stackAllocator; //Create an instance
|
||||
// cRZRect* pRectArray = stackAllocator.New(nSize); //Allocate memory, it will auto-freed.
|
||||
// pRectArray[0].SetRect(0,0,1,1); //Do something with the memory.
|
||||
// }
|
||||
//
|
||||
// void Example(int nSize){
|
||||
// StackAllocator<char, 200> stackAllocator; //Create an instance
|
||||
// char* pArray = stackAllocator.New(nSize); //Allocate memory.
|
||||
// char* pArray2 = stackAllocator.New(nSize); //Allocate some additional memory.
|
||||
// memset(pArray, 0, nSize*sizeof(char)); //Do something with the memory.
|
||||
// stackAllocator.Delete(pArray); //Delete the memory
|
||||
// pArray = stackAllocator.New(nSize*2); //Allocate some new memory. We'll let the allocator free it.
|
||||
// memset(pArray, 0, nSize*2*sizeof(char)); //Do something with the new memory.
|
||||
// stackAllocator.Delete(pArray2); //Delete the additional memory.
|
||||
// }
|
||||
//
|
||||
template<class T, int nStackCount, int bConstruct=1>
|
||||
class StackAllocator{
|
||||
public:
|
||||
StackAllocator() : mnAllocCount(-1), mpTHeap(NULL){}
|
||||
~StackAllocator(){
|
||||
if(mnAllocCount != -1){ //If there is anything to do...
|
||||
if(mpTHeap)
|
||||
delete mpTHeap;
|
||||
else{
|
||||
if(bConstruct){ //Since this constant, the comparison gets optimized away.
|
||||
T* pTArray = (T*)mTArray;
|
||||
const T* const pTArrayEnd = pTArray + mnAllocCount;
|
||||
while(pTArray < pTArrayEnd){
|
||||
pTArray->~T(); //Call the destructor on the object directly.
|
||||
++pTArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T* New(unsigned nCount){
|
||||
if(mnAllocCount == -1){
|
||||
mnAllocCount = nCount;
|
||||
if(nCount < nStackCount){ //If the request is small enough to come from the stack...
|
||||
//We call the constructors of all the objects here.
|
||||
if(bConstruct){ //Since this constant, the comparison gets optimized away.
|
||||
T* pTArray = (T*)mTArray;
|
||||
const T* const pTArrayEnd = pTArray + nCount;
|
||||
while(pTArray < pTArrayEnd){
|
||||
new(pTArray)T; //Use the placement operator new. This simply calls the constructor
|
||||
++pTArray; //of T with 'this' set to the input address. Note that we don't put
|
||||
} //a '()' after the T this is because () causes trivial types like int
|
||||
} //and class* to be assigned zero/NULL. We don't want that.
|
||||
return (T*)mTArray;
|
||||
} //Else the request is too big. So let's use (the slower) operator new.
|
||||
return (mpTHeap = new T[nCount]); //The compiler will call the constructors here.
|
||||
} //Else we are being used. Let's be nice and allocate something anyway.
|
||||
return new T[nCount];
|
||||
}
|
||||
|
||||
void Delete(T* pT){
|
||||
if(pT == (T*)mTArray){ //If the allocation came from our stack...
|
||||
if(bConstruct){ //Since this constant, the comparison gets optimized away.
|
||||
T* pTArray = (T*)mTArray;
|
||||
const T* const pTArrayEnd = pTArray + mnAllocCount;
|
||||
while(pTArray < pTArrayEnd){
|
||||
pTArray->~T(); //Call the destructor on the object directly.
|
||||
++pTArray;
|
||||
}
|
||||
}
|
||||
mnAllocCount = -1;
|
||||
}
|
||||
else if(pT == mpTHeap){ //If the allocation came from our heap...
|
||||
delete[] mpTHeap; //The compiler will call the destructors here.
|
||||
mpTHeap = NULL; //We clear these out so that we can possibly
|
||||
mnAllocCount = -1; // use the allocator again.
|
||||
}
|
||||
else //Else the allocation came from the external heap.
|
||||
delete[] pT;
|
||||
}
|
||||
|
||||
protected:
|
||||
int mnAllocCount; //Count of objects allocated. -1 means that nothing is allocated. We don't use zero because zero is a legal allocation count in C++.
|
||||
T* mpTHeap; //This is normally NULL, but gets used of the allocation request is too high.
|
||||
char mTArray[nStackCount*sizeof(T)]; //This is our stack memory.
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class FastFixedAllocator
|
||||
//
|
||||
class FastFixedAllocator
|
||||
{
|
||||
public:
|
||||
FastFixedAllocator(unsigned int n=0);
|
||||
~FastFixedAllocator();
|
||||
void Init(unsigned int n); //Useful for setting allocation size *after* construction,
|
||||
//but before first use.
|
||||
void* Alloc();
|
||||
void Free(void* pAlloc);
|
||||
|
||||
unsigned Get_Heap_Size() const { return TotalHeapSize; }
|
||||
unsigned Get_Allocated_Size() const { return TotalAllocatedSize; }
|
||||
unsigned Get_Allocation_Count() const { return TotalAllocationCount; }
|
||||
|
||||
protected:
|
||||
struct Link
|
||||
{
|
||||
Link* next;
|
||||
};
|
||||
|
||||
struct Chunk
|
||||
{
|
||||
enum {
|
||||
size = 8*1024-16
|
||||
};
|
||||
|
||||
Chunk* next;
|
||||
char mem[size];
|
||||
};
|
||||
Chunk* chunks;
|
||||
unsigned int esize;
|
||||
unsigned TotalHeapSize;
|
||||
unsigned TotalAllocatedSize;
|
||||
unsigned TotalAllocationCount;
|
||||
Link* head;
|
||||
void grow();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE void* FastFixedAllocator::Alloc()
|
||||
{
|
||||
TotalAllocationCount++;
|
||||
TotalAllocatedSize+=esize;
|
||||
if (head==0) {
|
||||
grow();
|
||||
}
|
||||
Link* p = head;
|
||||
head = p->next;
|
||||
return p;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE void FastFixedAllocator::Free(void* pAlloc)
|
||||
{
|
||||
TotalAllocationCount--;
|
||||
TotalAllocatedSize-=esize;
|
||||
Link* p = static_cast<Link*>(pAlloc);
|
||||
p->next = head;
|
||||
head = p;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE FastFixedAllocator::FastFixedAllocator(unsigned int n) : esize(1), TotalHeapSize(0), TotalAllocatedSize(0), TotalAllocationCount(0)
|
||||
{
|
||||
head = 0;
|
||||
chunks = 0;
|
||||
Init(n);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE FastFixedAllocator::~FastFixedAllocator()
|
||||
{
|
||||
Chunk* n = chunks;
|
||||
while(n){
|
||||
Chunk* p = n;
|
||||
n = n->next;
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE void FastFixedAllocator::Init(unsigned int n)
|
||||
{
|
||||
esize = (n<sizeof(Link*) ? sizeof(Link*) : n);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE void FastFixedAllocator::grow()
|
||||
{
|
||||
Chunk* n = new Chunk;
|
||||
n->next = chunks;
|
||||
chunks = n;
|
||||
TotalHeapSize+=sizeof(Chunk);
|
||||
|
||||
const int nelem = Chunk::size/esize;
|
||||
char* start = n->mem;
|
||||
char* last = &start[(nelem-1)*esize];
|
||||
for(char* p = start; p<last; p+=esize)
|
||||
reinterpret_cast<Link*>(p)->next = reinterpret_cast<Link*>(p+esize);
|
||||
reinterpret_cast<Link*>(last)->next = 0;
|
||||
head = reinterpret_cast<Link*>(start);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class FastAllocatorGeneral
|
||||
//
|
||||
// This class works by putting sizes into fixed size buckets. Each fixed size
|
||||
// bucket is a FastFixedAllocator.
|
||||
//
|
||||
class FastAllocatorGeneral
|
||||
{
|
||||
enum {
|
||||
MAX_ALLOC_SIZE=2048,
|
||||
ALLOC_STEP=16
|
||||
};
|
||||
public:
|
||||
FastAllocatorGeneral();
|
||||
void* Alloc(unsigned int n);
|
||||
void Free(void* pAlloc);
|
||||
void* Realloc(void* pAlloc, unsigned int n);
|
||||
|
||||
unsigned Get_Total_Heap_Size();
|
||||
unsigned Get_Total_Allocated_Size();
|
||||
unsigned Get_Total_Allocation_Count();
|
||||
unsigned Get_Total_Actual_Memory_Usage() { return ActualMemoryUsage; }
|
||||
|
||||
static FastAllocatorGeneral* Get_Allocator();
|
||||
|
||||
protected:
|
||||
FastFixedAllocator allocators[MAX_ALLOC_SIZE/ALLOC_STEP];
|
||||
FastCriticalSectionClass CriticalSections[MAX_ALLOC_SIZE/ALLOC_STEP];
|
||||
bool MemoryLeakLogEnabled;
|
||||
|
||||
unsigned AllocatedWithMalloc;
|
||||
unsigned AllocatedWithMallocCount;
|
||||
unsigned ActualMemoryUsage;
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WWINLINE unsigned FastAllocatorGeneral::Get_Total_Heap_Size()
|
||||
{
|
||||
int size=AllocatedWithMalloc;
|
||||
for (int i=0;i<MAX_ALLOC_SIZE/ALLOC_STEP;++i) {
|
||||
FastCriticalSectionClass::LockClass lock(CriticalSections[i]);
|
||||
size+=allocators[i].Get_Heap_Size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
WWINLINE unsigned FastAllocatorGeneral::Get_Total_Allocated_Size()
|
||||
{
|
||||
int size=AllocatedWithMalloc;
|
||||
for (int i=0;i<MAX_ALLOC_SIZE/ALLOC_STEP;++i) {
|
||||
FastCriticalSectionClass::LockClass lock(CriticalSections[i]);
|
||||
size+=allocators[i].Get_Allocated_Size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
WWINLINE unsigned FastAllocatorGeneral::Get_Total_Allocation_Count()
|
||||
{
|
||||
int count=AllocatedWithMallocCount;
|
||||
for (int i=0;i<MAX_ALLOC_SIZE/ALLOC_STEP;++i) {
|
||||
FastCriticalSectionClass::LockClass lock(CriticalSections[i]);
|
||||
count+=allocators[i].Get_Allocation_Count();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE void* FastAllocatorGeneral::Alloc(unsigned int n)
|
||||
{
|
||||
void* pMemory;
|
||||
static int re_entrancy=0;
|
||||
re_entrancy++;
|
||||
|
||||
//We actually allocate n+4 bytes. We store the # allocated
|
||||
//in the first 4 bytes, and return the ptr to the rest back
|
||||
//to the user.
|
||||
n += sizeof(unsigned int);
|
||||
#ifdef MEMORY_OVERWRITE_TEST
|
||||
n+=sizeof(unsigned int);
|
||||
#endif
|
||||
|
||||
if (re_entrancy==1) {
|
||||
ActualMemoryUsage+=n;
|
||||
}
|
||||
if (n<MAX_ALLOC_SIZE) {
|
||||
int index=(n)/ALLOC_STEP;
|
||||
{
|
||||
FastCriticalSectionClass::LockClass lock(CriticalSections[index]);
|
||||
pMemory = allocators[index].Alloc();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (re_entrancy==1) {
|
||||
AllocatedWithMalloc+=n;
|
||||
AllocatedWithMallocCount++;
|
||||
}
|
||||
pMemory = ::malloc(n);
|
||||
}
|
||||
#ifdef MEMORY_OVERWRITE_TEST
|
||||
*((unsigned int*)((char*)pMemory+n)-1)=0xabbac0de;
|
||||
#endif
|
||||
|
||||
re_entrancy--;
|
||||
*((unsigned int*)pMemory) = n; //Write modified (augmented by 4) count into first four bytes.
|
||||
return ((unsigned int*)pMemory)+1; //return ptr to bytes after it back to user.
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WWINLINE void FastAllocatorGeneral::Free(void* pAlloc)
|
||||
{
|
||||
if (pAlloc) {
|
||||
unsigned int* n = ((unsigned int*)pAlloc)-1; //Subtract four bytes and the count is stored there.
|
||||
|
||||
#ifdef MEMORY_OVERWRITE_TEST
|
||||
WWASSERT(*((unsigned int*)((char*)n+*n)-1)==0xabbac0de);
|
||||
#endif
|
||||
|
||||
unsigned size=*n;
|
||||
ActualMemoryUsage-=size;
|
||||
|
||||
if (size<MAX_ALLOC_SIZE) {
|
||||
int index=size/ALLOC_STEP;
|
||||
FastCriticalSectionClass::LockClass lock(CriticalSections[index]);
|
||||
allocators[index].Free(n);
|
||||
}
|
||||
else {
|
||||
AllocatedWithMallocCount--;
|
||||
AllocatedWithMalloc-=size;
|
||||
::free(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ANSI C requires:
|
||||
// (1) realloc(NULL, newsize) is equivalent to malloc(newsize).
|
||||
// (2) realloc(pblock, 0) is equivalent to free(pblock) (except that NULL is returned).
|
||||
// (3) if the realloc() fails, the object pointed to by pblock is left unchanged.
|
||||
//
|
||||
WWINLINE void* FastAllocatorGeneral::Realloc(void* pAlloc, unsigned int n){
|
||||
if(n){
|
||||
void* const pNewAlloc = Alloc(n); //Allocate the new memory. This never fails.
|
||||
if(pAlloc){
|
||||
n = *(((unsigned int*)pAlloc)-1); //Subtract four bytes and the count is stored there.
|
||||
::memcpy(pNewAlloc, pAlloc, n); //Copy the old memory into the new memory.
|
||||
Free(pAlloc); //Delete the old memory.
|
||||
}
|
||||
return pNewAlloc;
|
||||
}
|
||||
Free(pAlloc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FastSTLAllocator
|
||||
//
|
||||
// An STL allocator based on a simple fixed size allocator is not going to
|
||||
// buy you the performance you really want. This is because STL containers
|
||||
// allocate not just objects of the size of the container, but other objects
|
||||
// as well. For example, the STL "list" class generally allocates item nodes
|
||||
// and not items themselves. The STL vector class usually allocates in chunks
|
||||
// of contiguous items. So your allocator will probably want to have a bucket
|
||||
// system whereby it maintains buckets for integral sizes.
|
||||
//
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//VC++ continues to be the one compiler that lacks the ability to compile
|
||||
//standard C++. So we define a version of the STL allocator specifically
|
||||
//for VC++, and let other compilers use a standard allocator template.
|
||||
template <class T>
|
||||
struct FastSTLAllocator{
|
||||
typedef size_t size_type; //basically, "unsigned int"
|
||||
typedef ptrdiff_t difference_type; //basically, "int"
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
|
||||
T* address(T& t) const { return (&t); } //These two are slightly strange but
|
||||
const T* address(const T& t) const { return (&t); } //required functions. Just do it.
|
||||
static T* allocate(size_t n, const void* =NULL) { return (T*)generalAllocator.Alloc(n*sizeof(T)); }
|
||||
static void construct(T* ptr, const T& value) { new(ptr) T(value); }
|
||||
static void deallocate(void* ptr, size_t /*n*/) { generalAllocator.Free(ptr); }
|
||||
static void destroy(T* ptr) { ptr->~T(); }
|
||||
static size_t max_size() { return (size_t)-1; }
|
||||
|
||||
//This _Charalloc is required by VC++5 since it VC++5 predates
|
||||
//the language standardization. Allocator behaviour is one of the
|
||||
//last things to have been hammered out. Important note: If you
|
||||
//decide to write your own fast allocator, containers will allocate
|
||||
//random objects through this function but delete them through
|
||||
//the above delallocate() function. So your version of deallocate
|
||||
//should *not* assume that it will only be given T objects to delete.
|
||||
char* _Charalloc(size_t n){ return (char*)::generalAllocator.Alloc(n*sizeof(char)); }
|
||||
};
|
||||
#else
|
||||
//This is a C++ language standard allocator. Most C++ compilers after 1999
|
||||
//other than Microsoft C++ compile this fine. Otherwise. you might be able
|
||||
//to use the same allocator as VC++ uses above.
|
||||
template <class T>
|
||||
class FastSTLAllocator{
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
|
||||
template <class T1> struct rebind {
|
||||
typedef FastSTLAllocator<T1> other;
|
||||
};
|
||||
|
||||
FastSTLAllocator() {}
|
||||
FastSTLAllocator(const FastSTLAllocator&) {}
|
||||
template <class T1> FastSTLAllocator(const FastSTLAllocator<T1>&) {}
|
||||
~FastSTLAllocator() {}
|
||||
|
||||
pointer address(reference x) const { return &x; }
|
||||
const_pointer address(const_reference x) const { return &x; }
|
||||
|
||||
T* allocate(size_type n, const void* = NULL) { return n != 0 ? static_cast<T*>(generalAllocator.Alloc(n*sizeof(T))) : NULL; }
|
||||
void deallocate(pointer p, size_type n) { generalAllocator.Free(p); }
|
||||
size_type max_size() const { return size_t(-1) / sizeof(T); }
|
||||
void construct(pointer p, const T& val) { new(p) T(val); }
|
||||
void destroy(pointer p) { p->~T(); }
|
||||
};
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
WWINLINE bool operator==(const FastSTLAllocator<T>&, const FastSTLAllocator<T>&) { return true; }
|
||||
template<class T>
|
||||
WWINLINE bool operator!=(const FastSTLAllocator<T>&, const FastSTLAllocator<T>&) { return false; }
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Example usage of fast allocators in STL.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <hash_set> //Uncomment this if you have hash containers available.
|
||||
#include <hash_map>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Here's how you declare a custom allocator for every regular STL container class:
|
||||
//
|
||||
typedef vector<int, FastSTLAllocator<int> > IntArray;
|
||||
typedef list<int, FastSTLAllocator<int> > IntList;
|
||||
typedef deque<int, FastSTLAllocator<int> > IntDequeue;
|
||||
typedef queue<int, deque<int, FastSTLAllocator<int> > > IntQueue;
|
||||
typedef priority_queue<int, vector<int, FastSTLAllocator<int> > > IntPriorityQueue;
|
||||
typedef stack<int, deque<int, FastSTLAllocator<int> > > IntStack;
|
||||
typedef map<int, int, less<int>, FastSTLAllocator<int> > IntMap;
|
||||
typedef multimap<int, int, less<int>, FastSTLAllocator<int> > IntMultiMap;
|
||||
typedef set<int, less<int>, FastSTLAllocator<int> > IntSet;
|
||||
typedef multiset<int, less<int>, FastSTLAllocator<int> > IntMultiSet;
|
||||
|
||||
//If you have the hashing containers available, here's how you do it:
|
||||
typedef hash_map<int, int, hash<int>, equal_to<int>, FastSTLAllocator<int> > IntHashMap;
|
||||
typedef hash_multimap<int, int, hash<int>, equal_to<int>, FastSTLAllocator<int> > IntHashMultiMap;
|
||||
typedef hash_set<int, hash<int>, equal_to<int>, FastSTLAllocator<int> > IntHashSet;
|
||||
typedef hash_multiset<int, hash<int>, equal_to<int>, FastSTLAllocator<int> > IntHashMultiSet;
|
||||
|
||||
typedef basic_string<char, char_traits<char>, FastSTLAllocator<char> > CharString;
|
||||
|
||||
//bitset and valarray don't allow custom allocators.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void main(){
|
||||
IntArray intArray;
|
||||
intArray.push_back(3);
|
||||
intArray.pop_back();
|
||||
|
||||
IntList intList;
|
||||
intList.push_back(3);
|
||||
intList.pop_back();
|
||||
|
||||
IntDequeue intDequeue;
|
||||
intDequeue.push_back(3);
|
||||
intDequeue.pop_back();
|
||||
|
||||
IntQueue intQueue;
|
||||
intQueue.push(3);
|
||||
intQueue.pop();
|
||||
|
||||
IntPriorityQueue intPriorityQueue;
|
||||
intPriorityQueue.push(3);
|
||||
intPriorityQueue.pop();
|
||||
|
||||
IntStack intStack;
|
||||
intStack.push(3);
|
||||
intStack.pop();
|
||||
|
||||
IntMap intMap;
|
||||
intMap.insert(pair<int,int>(3,3));
|
||||
intMap.erase(3);
|
||||
|
||||
IntMultiMap intMultiMap;
|
||||
intMultiMap.insert(pair<int,int>(3,3));
|
||||
intMultiMap.erase(3);
|
||||
|
||||
IntSet intSet;
|
||||
intSet.insert(3);
|
||||
intSet.erase(3);
|
||||
|
||||
IntMultiSet intMultiSet;
|
||||
intMultiSet.insert(3);
|
||||
intMultiSet.erase(3);
|
||||
|
||||
IntHashMap intHashMap;
|
||||
intHashMap.insert(3);
|
||||
intHashMap.erase(3);
|
||||
|
||||
IntHashMultiMap intHashMultiMap;
|
||||
intHashMultiMap.insert(3);
|
||||
intHashMultiMap.erase(3);
|
||||
|
||||
IntHashSet intHashSet;
|
||||
intHashSet.insert(3);
|
||||
intHashSet.erase(3);
|
||||
|
||||
IntHashMultiSet intHashMultiSet;
|
||||
intHashMultiSet.insert(3);
|
||||
intHashMultiSet.erase(3);
|
||||
|
||||
CharString charString;
|
||||
charString.append(1, '3');
|
||||
charString.erase(charString.length()-1);
|
||||
|
||||
//Shutdown
|
||||
printf("\nDone. Press the 'any' key\n");
|
||||
getchar();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif //sentry
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
120
Code/wwlib/LaunchWeb.cpp
Normal file
120
Code/wwlib/LaunchWeb.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* FILE
|
||||
* $Archive: /Commando/Code/wwlib/LaunchWeb.cpp $
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Denzil E. Long, Jr.
|
||||
* $Author: Denzil_l $
|
||||
*
|
||||
* VERSION INFO
|
||||
* $Revision: 2 $
|
||||
* $Modtime: 6/22/01 4:39p $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "LaunchWeb.h"
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* LaunchWebBrowser
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Launch the default browser to view the specified URL
|
||||
*
|
||||
* INPUTS
|
||||
* URL - Website address
|
||||
* Wait - Wait for user to close browser (default = false)
|
||||
* Callback - User callback to invoke during wait (default = NULL callback)
|
||||
*
|
||||
* RESULT
|
||||
* Success - True if successful; otherwise false
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
bool LaunchWebBrowser(const char* url)
|
||||
{
|
||||
// Just return if no URL specified
|
||||
if (!url || (strlen(url) == 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a temporary file with HTML content
|
||||
char tempPath[MAX_PATH];
|
||||
GetWindowsDirectory(tempPath, MAX_PATH);
|
||||
|
||||
char filename[MAX_PATH];
|
||||
GetTempFileName(tempPath, "WWS", 0, filename);
|
||||
|
||||
char* extPtr = strrchr(filename, '.');
|
||||
strcpy(extPtr, ".html");
|
||||
|
||||
HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
assert(INVALID_HANDLE_VALUE != file && "Failed to create temporary HTML file.");
|
||||
|
||||
if (INVALID_HANDLE_VALUE == file)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write generic contents
|
||||
const char* contents = "<title>ViewHTML</title>";
|
||||
DWORD written;
|
||||
WriteFile(file, contents, strlen(contents), &written, NULL);
|
||||
CloseHandle(file);
|
||||
|
||||
// Find the executable that can launch this file
|
||||
char exeName[MAX_PATH];
|
||||
HINSTANCE hInst = FindExecutable(filename, NULL, exeName);
|
||||
assert(((int)hInst > 32) && "Unable to find executable that will display HTML files.");
|
||||
|
||||
// Delete temporary file
|
||||
DeleteFile(filename);
|
||||
|
||||
if ((int)hInst <= 32)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Launch browser with specified URL
|
||||
char commandLine[MAX_PATH];
|
||||
sprintf(commandLine, "[open] %s", url);
|
||||
|
||||
STARTUPINFO startupInfo;
|
||||
memset(&startupInfo, 0, sizeof(startupInfo));
|
||||
startupInfo.cb = sizeof(startupInfo);
|
||||
|
||||
PROCESS_INFORMATION processInfo;
|
||||
BOOL createSuccess = CreateProcess(exeName, commandLine, NULL, NULL, FALSE,
|
||||
0, NULL, NULL, &startupInfo, &processInfo);
|
||||
|
||||
assert(createSuccess && "Failed to launch default WebBrowser.");
|
||||
|
||||
return (TRUE == createSuccess);
|
||||
}
|
||||
48
Code/wwlib/LaunchWeb.h
Normal file
48
Code/wwlib/LaunchWeb.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* FILE
|
||||
* $Archive: /Commando/Code/wwlib/LaunchWeb.h $
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Denzil E. Long, Jr.
|
||||
* $Author: Denzil_l $
|
||||
*
|
||||
* VERSION INFO
|
||||
* $Revision: 1 $
|
||||
* $Modtime: 4/20/01 3:22p $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __LAUNCHWEB_H__
|
||||
#define __LAUNCHWEB_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool LaunchWebBrowser(const char* url);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // __LAUNCHWEB_H__
|
||||
275
Code/wwlib/Notify.h
Normal file
275
Code/wwlib/Notify.h
Normal file
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* FILE
|
||||
* $Archive: /Commando/Code/wwlib/Notify.h $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* These templates provide implementation of the Subject-Observer pattern.
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Steve Clinard
|
||||
* $Author: Denzil_l $
|
||||
*
|
||||
* VERSION INFO
|
||||
* $Modtime: 11/13/01 10:49a $
|
||||
* $Revision: 8 $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __NOTIFY_H__
|
||||
#define __NOTIFY_H__
|
||||
|
||||
// Reduce warning level for STL
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push, 3)
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
template<typename Event> class Notifier;
|
||||
template<typename Event> class Observer;
|
||||
|
||||
template<typename Event> class Observer
|
||||
{
|
||||
public:
|
||||
typedef std::vector< Notifier<Event>* > NotifierColl;
|
||||
|
||||
Observer() :
|
||||
mNotifiers(NULL)
|
||||
{}
|
||||
|
||||
virtual ~Observer()
|
||||
{StopObserving();}
|
||||
|
||||
//! Handle event notification
|
||||
virtual void HandleNotification(Event&) = 0;
|
||||
|
||||
//! Notifier has ended notification of this event
|
||||
virtual void NotificationEnded(const Notifier<Event>& notifier)
|
||||
{
|
||||
NotifierColl::iterator pos = std::find(mNotifiers.begin(),
|
||||
mNotifiers.end(), ¬ifier);
|
||||
|
||||
if (pos != mNotifiers.end())
|
||||
{
|
||||
mNotifiers.erase(pos);
|
||||
}
|
||||
}
|
||||
|
||||
//! Request notification of this event
|
||||
virtual void NotifyMe(Notifier<Event>& notifier)
|
||||
{notifier.AddObserver(*this);}
|
||||
|
||||
//! Stop observing event
|
||||
void StopObserving()
|
||||
{
|
||||
while (mNotifiers.size() > 0)
|
||||
{
|
||||
Notifier<Event>* notifier = mNotifiers.back();
|
||||
assert(notifier && "ERROR: NULL pointer in collection.");
|
||||
notifier->RemoveObserver(*this);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Observer(const Observer<Event>& observer);
|
||||
const Observer<Event>& operator=(const Observer<Event>&);
|
||||
|
||||
private:
|
||||
friend class Notifier<Event>;
|
||||
NotifierColl mNotifiers;
|
||||
};
|
||||
|
||||
|
||||
#define DECLARE_OBSERVER(Event) \
|
||||
virtual void NotifyMe(Notifier<Event>& observer) \
|
||||
{Notifier<Event>::AddObserver(observer);}
|
||||
|
||||
|
||||
template<typename Event> class Notifier
|
||||
{
|
||||
public:
|
||||
typedef std::vector< Observer<Event>* > ObserverColl;
|
||||
|
||||
Notifier()
|
||||
{}
|
||||
|
||||
virtual ~Notifier()
|
||||
{
|
||||
for (int index = mObservers.size(); index--;)
|
||||
{
|
||||
mObservers[index]->NotificationEnded(*this);
|
||||
}
|
||||
}
|
||||
|
||||
//! Send event notification to all observers of this event.
|
||||
virtual void NotifyObservers(Event& event)
|
||||
{
|
||||
for (unsigned int index = 0; index < mObservers.size(); index++)
|
||||
{
|
||||
mObservers[index]->HandleNotification(event);
|
||||
}
|
||||
}
|
||||
|
||||
//! Add an observer of this event
|
||||
virtual void AddObserver(Observer<Event>& observer)
|
||||
{
|
||||
ObserverColl::iterator pos = std::find(mObservers.begin(),
|
||||
mObservers.end(), &observer);
|
||||
|
||||
if (pos == mObservers.end())
|
||||
{
|
||||
observer.mNotifiers.push_back(this);
|
||||
mObservers.push_back(&observer);
|
||||
}
|
||||
}
|
||||
|
||||
//! Remove an observer of this event
|
||||
virtual void RemoveObserver(Observer<Event>& observer)
|
||||
{
|
||||
ObserverColl::iterator pos = std::find(mObservers.begin(),
|
||||
mObservers.end(), &observer);
|
||||
|
||||
if (pos != mObservers.end())
|
||||
{
|
||||
observer.NotificationEnded(*this);
|
||||
mObservers.erase(pos);
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool HasObservers(void) const
|
||||
{return !mObservers.empty();}
|
||||
|
||||
private:
|
||||
//! Observer collection
|
||||
ObserverColl mObservers;
|
||||
};
|
||||
|
||||
|
||||
#define DECLARE_NOTIFIER(Event) \
|
||||
virtual void NotifyObservers(Event& event) \
|
||||
{Notifier<Event>::NotifyObservers(event);} \
|
||||
virtual void AddObserver(Observer<Event>& observer) \
|
||||
{Notifier<Event>::AddObserver(observer);} \
|
||||
virtual void RemoveObserver(Observer<Event>& observer) \
|
||||
{Notifier<Event>::RemoveObserver(observer);}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* The following templates are useful for defining unique types to use as
|
||||
* Events from types such as strings or integers.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* TypedEvent<T. V>
|
||||
*
|
||||
* The first type (T) must be a class or other unique type. This need not
|
||||
* be a "real" class. It could be a forward declared class, which is enough
|
||||
* to make the template class unique.
|
||||
*
|
||||
* The second type (V) is the event data. "UString" and "int" are obvious
|
||||
* choices.
|
||||
*
|
||||
* Typedef'ing the template class is a good thing to do.
|
||||
*/
|
||||
template<typename T, typename V>
|
||||
class TypedEvent
|
||||
{
|
||||
public:
|
||||
TypedEvent(V& value) :
|
||||
mValue(value)
|
||||
{}
|
||||
|
||||
inline V& operator()()
|
||||
{return mValue;}
|
||||
|
||||
inline V& Subject(void)
|
||||
{return mValue;}
|
||||
|
||||
protected:
|
||||
V& mValue;
|
||||
};
|
||||
|
||||
template<typename T, typename O>
|
||||
class TypedEventPtr
|
||||
{
|
||||
public:
|
||||
TypedEventPtr(O* subject) :
|
||||
mSubject(subject)
|
||||
{}
|
||||
|
||||
inline O* Subject(void)
|
||||
{return mSubject;}
|
||||
|
||||
inline O* operator()()
|
||||
{return mSubject;}
|
||||
|
||||
protected:
|
||||
O* mSubject;
|
||||
};
|
||||
|
||||
template<typename A, typename O>
|
||||
class TypedActionPtr :
|
||||
public TypedEventPtr<A, O>
|
||||
{
|
||||
public:
|
||||
A GetAction(void) const
|
||||
{return mAction;}
|
||||
|
||||
TypedActionPtr(A action, O* data) :
|
||||
TypedEventPtr<A, O>(data),
|
||||
mAction(action)
|
||||
{}
|
||||
|
||||
~TypedActionPtr()
|
||||
{}
|
||||
|
||||
protected:
|
||||
A mAction;
|
||||
};
|
||||
|
||||
template<typename A, typename B>
|
||||
class TypedEventPair
|
||||
{
|
||||
public:
|
||||
TypedEventPair(A itemA, B itemB) :
|
||||
mItemA(itemA),
|
||||
mItemB(itemB)
|
||||
{}
|
||||
|
||||
inline A GetItemA(void)
|
||||
{return mItemA;}
|
||||
|
||||
inline B GetItemB(void)
|
||||
{return mItemB;}
|
||||
|
||||
protected:
|
||||
A mItemA;
|
||||
B mItemB;
|
||||
};
|
||||
|
||||
#endif // __NOTIFY_H__
|
||||
85
Code/wwlib/Signaler.h
Normal file
85
Code/wwlib/Signaler.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* FILE
|
||||
* $Archive: /Commando/Code/wwlib/Signaler.h $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Lightweight two-way notification system. This class allows loose coupling
|
||||
* communication between two classes. The only details that need to be know
|
||||
* by both classes is the Signaler class it self and the type of signal they
|
||||
* communicate to each other.
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Denzil E. Long, Jr.
|
||||
* $Author: Denzil_l $
|
||||
*
|
||||
* VERSION INFO
|
||||
* $Modtime: 11/16/01 11:19a $
|
||||
* $Revision: 4 $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __SIGNALER_H__
|
||||
#define __SIGNALER_H__
|
||||
|
||||
template<typename T> class Signaler
|
||||
{
|
||||
public:
|
||||
void SignalMe(Signaler<T>& target)
|
||||
{if (mConnection != &target) {Disconnect(); Connect(target); target.Connect(*this);}}
|
||||
|
||||
void StopSignaling(Signaler<T>& target)
|
||||
{if (mConnection == &target) {Disconnect();}}
|
||||
|
||||
void SendSignal(T& signal)
|
||||
{if (mConnection) {mConnection->ReceiveSignal(signal);}}
|
||||
|
||||
virtual void ReceiveSignal(T&)
|
||||
{}
|
||||
|
||||
virtual void SignalDropped(Signaler<T>& signaler)
|
||||
{mConnection = NULL;}
|
||||
|
||||
protected:
|
||||
Signaler() :
|
||||
mConnection(NULL)
|
||||
{}
|
||||
|
||||
virtual ~Signaler()
|
||||
{Disconnect();}
|
||||
|
||||
void Connect(Signaler<T>& source)
|
||||
{mConnection = &source;}
|
||||
|
||||
void Disconnect(void)
|
||||
{if (mConnection) {mConnection->SignalDropped(*this);} mConnection = NULL;}
|
||||
|
||||
// Prevent copy and assignment
|
||||
Signaler(const Signaler&);
|
||||
const Signaler& operator=(const Signaler&);
|
||||
|
||||
private:
|
||||
Signaler<T>* mConnection;
|
||||
};
|
||||
|
||||
#endif // __SIGNALER_H__
|
||||
|
||||
|
||||
1397
Code/wwlib/TARGA.CPP
Normal file
1397
Code/wwlib/TARGA.CPP
Normal file
File diff suppressed because it is too large
Load Diff
320
Code/wwlib/TARGA.H
Normal file
320
Code/wwlib/TARGA.H
Normal file
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TARGA_H_
|
||||
#define _TARGA_H_
|
||||
/****************************************************************************
|
||||
*
|
||||
* C O N F I D E N T I A L --- W E S T W O O D S T U D I O S
|
||||
*
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* FILE
|
||||
* Targa.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Targa image file class definitions.
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Denzil E. Long, Jr.
|
||||
*
|
||||
* DATE
|
||||
* July 15, 1998
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
// If you wish to display loading error messages call targa functions inside of
|
||||
// the following macro - for example TARGA_ERROR_HANDLER(targa.Open(filename, TGA_READMODE));
|
||||
// The error code is returned back from the handler so it can be used in an expression.
|
||||
long Targa_Error_Handler(long error_code,const char* filename);
|
||||
#define TARGA_ERROR_HANDLER(call,filename) Targa_Error_Handler(call,filename)
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* STRUCTURES AND RELATED DEFINITIONS
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/* TGAHeader - Targa Image File header.
|
||||
*
|
||||
* IDLength - Size of Image ID field
|
||||
* ColorMapType - Color map type.
|
||||
* ImageType - Image type code.
|
||||
* CMapStart - Color map origin.
|
||||
* CMapLength - Color map length.
|
||||
* CMapDepth - Depth of color map entries.
|
||||
* XOffset - X origin of image.
|
||||
* YOffset - Y origin of image.
|
||||
* Width - Width of image.
|
||||
* Height - Height of image.
|
||||
* PixelDepth - Image pixel size
|
||||
* ImageDescriptor - Image descriptor byte.
|
||||
*/
|
||||
typedef struct _TGAHeader
|
||||
{
|
||||
char IDLength;
|
||||
char ColorMapType;
|
||||
char ImageType;
|
||||
short CMapStart;
|
||||
short CMapLength;
|
||||
char CMapDepth;
|
||||
short XOffset;
|
||||
short YOffset;
|
||||
short Width;
|
||||
short Height;
|
||||
char PixelDepth;
|
||||
char ImageDescriptor;
|
||||
} TGAHeader;
|
||||
|
||||
/* ImageType definiton */
|
||||
#define TGA_NOIMAGE 0 /* No image data included in file */
|
||||
#define TGA_CMAPPED 1 /* Color-mapped image data */
|
||||
#define TGA_TRUECOLOR 2 /* Truecolor image data */
|
||||
#define TGA_MONO 3 /* Monochrome image data */
|
||||
#define TGA_CMAPPED_ENCODED 9 /* Color-mapped image data (Encoded) */
|
||||
#define TGA_TRUECOLOR_ENCODED 10 /* Truecolor image data (Encoded) */
|
||||
#define TGA_MONO_ENCODED 11 /* Monochrome image data (Encoded) */
|
||||
|
||||
/* ImageDescriptor definition */
|
||||
#define TGAIDF_ATTRIB_BITS (0x0F<<0) /* Number of attribute bits per pixel */
|
||||
#define TGAIDF_XORIGIN (1<<4)
|
||||
#define TGAIDF_YORIGIN (1<<5)
|
||||
|
||||
/* Access modes. */
|
||||
#define TGA_READMODE 0
|
||||
#define TGA_WRITEMODE 1
|
||||
#define TGA_RDWRMODE 2
|
||||
|
||||
/* Error codes */
|
||||
#define TGAERR_OPEN -1
|
||||
#define TGAERR_READ -2
|
||||
#define TGAERR_WRITE -3
|
||||
#define TGAERR_SYNTAX -4
|
||||
#define TGAERR_NOMEM -5
|
||||
#define TGAERR_NOTSUPPORTED -6
|
||||
|
||||
/* Flags definitions */
|
||||
#define TGAF_IMAGE (1<<0)
|
||||
#define TGAF_PAL (1<<1)
|
||||
#define TGAF_COMPRESS (1<<2)
|
||||
#define TGAF_TGA2 (1<<3)
|
||||
|
||||
/* Macro definitions */
|
||||
#define TGA_BytesPerPixel(a) ((a+7) >> 3)
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* TARGA 2.0 DEFINITIONS
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
#define TGA2_SIGNATURE "TRUEVISION-XFILE"
|
||||
|
||||
/* TGA2Footer - Targa 2.0 footer
|
||||
*
|
||||
* Extension - Offset to the Extension area from start of file.
|
||||
* Developer - Offset to the Developer area from start of file.
|
||||
* Signature - 16 byte Targa 2.0 signature "TRUEVISION-XFILE"
|
||||
* RsvdChar - Reserved character, must be ASCII "." (period)
|
||||
* BZST - Binary Zero String Terminator.
|
||||
*/
|
||||
typedef struct _TGA2Footer
|
||||
{
|
||||
long Extension;
|
||||
long Developer;
|
||||
char Signature[16];
|
||||
char RsvdChar;
|
||||
char BZST;
|
||||
_TGA2Footer() {}
|
||||
} TGA2Footer;
|
||||
|
||||
/* TGA2DateStamp - A series of 3 WORD values which define the integer value
|
||||
* for the date the image was saved.
|
||||
*
|
||||
* Month - Month number (1 - 12)
|
||||
* Day - Day number (1 - 31)
|
||||
* Year - Year number (4 digit, ie. 1989)
|
||||
*/
|
||||
typedef struct _TGA2DateStamp
|
||||
{
|
||||
short Month;
|
||||
short Day;
|
||||
short Year;
|
||||
} TGA2DateStamp;
|
||||
|
||||
/* TGA2TimeStamp - A series of 3 WORD values which define the integer value
|
||||
* for the time the image was saved.
|
||||
*
|
||||
* Hour - Hour number, military time (0 - 23)
|
||||
* Minute - Minute number (0 - 59)
|
||||
* Second - Second number (0 - 59)
|
||||
*/
|
||||
typedef struct _TGA2TimeStamp
|
||||
{
|
||||
short Hour;
|
||||
short Minute;
|
||||
short Second;
|
||||
} TGA2TimeStamp;
|
||||
|
||||
/* TGA2SoftVer - Define the version of the software used to generate file.
|
||||
*
|
||||
* Number - Version number * 100
|
||||
* Letter - Version letter
|
||||
*/
|
||||
typedef struct _TGA2SoftVer
|
||||
{
|
||||
short Number;
|
||||
char Letter;
|
||||
} TGA2SoftVer;
|
||||
|
||||
/* TGA2Ratio - Numerator and denominator which when taken together specify
|
||||
* a ratio.
|
||||
*
|
||||
* Numer - Numerator
|
||||
* Denom - Denominator (a value of zero indicates no ratio specified)
|
||||
*/
|
||||
typedef struct _TGA2Ratio
|
||||
{
|
||||
short Numer;
|
||||
short Denom;
|
||||
} TGA2Ratio;
|
||||
|
||||
/* TGA2Extension - Extension area, provided for additional file information.
|
||||
* This data is pointed to by the Extension offset in the
|
||||
* TGA2Footer.
|
||||
*
|
||||
* ExtSize - Extension area size. (495 bytes for 2.0)
|
||||
* AuthName - Name of the person who created image (NULL terminated ASCII)
|
||||
* AuthComment - Comments of the author (NULL terminated ASCII)
|
||||
* DateStamp - Date the file was created. (See TGA2DateStamp)
|
||||
* TimeStamp - Time the file was created. (See TGA2TimeStamp)
|
||||
* JobName - Name of job image belongs to (NULL terminated ASCII)
|
||||
* JobTime - Elapsed time of the job.
|
||||
* SoftID - ID of software used to create image (NULL terminated ASCII)
|
||||
* SoftVer - Version number of software used.
|
||||
* KeyColor - Tranparent color value.
|
||||
* Aspect - Pixel aspect ratio.
|
||||
* Gamma - Fractional gamma value.
|
||||
* ColorCor - Color correction table offset.
|
||||
* PostStamp - Postage stamp image offset.
|
||||
* ScanLine - Scan line table offset.
|
||||
* Attributes - Alpha channel attributes. (Set defines below)
|
||||
*/
|
||||
typedef struct _TGA2Extension
|
||||
{
|
||||
short ExtSize;
|
||||
char AuthName[41];
|
||||
char AuthComment[324];
|
||||
TGA2DateStamp Date;
|
||||
TGA2TimeStamp Time;
|
||||
char JobName[41];
|
||||
TGA2TimeStamp JobTime;
|
||||
char SoftID[41];
|
||||
TGA2SoftVer SoftVer;
|
||||
long KeyColor;
|
||||
TGA2Ratio Aspect;
|
||||
TGA2Ratio Gamma;
|
||||
long ColorCor;
|
||||
long PostStamp;
|
||||
long ScanLine;
|
||||
char Attributes;
|
||||
} TGA2Extension;
|
||||
|
||||
/* Alpha channel attributes (Extension Area) */
|
||||
#define EXTA_NOALPHA 0 /* No alpha data included */
|
||||
#define EXTA_IGNORE 1 /* Undefined alpha data, can ignore */
|
||||
#define EXTA_RETAIN 2 /* Undefined alpha data, should retain */
|
||||
#define EXTA_USEFUL 3 /* Useful alpha channel */
|
||||
#define EXTA_PREMULT 4 /* Pre-Multiplied alpha data */
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
/*
|
||||
** This define changes this code from code that works with standard IO calls,
|
||||
** to code that uses FileClass and FileFactoryClass.
|
||||
*/
|
||||
#define TGA_USES_WWLIB_FILE_CLASSES
|
||||
|
||||
#ifdef TGA_USES_WWLIB_FILE_CLASSES
|
||||
class FileClass;
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* CLASS DEFINITION
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
class Targa
|
||||
{
|
||||
public:
|
||||
/* Constructor/destructor */
|
||||
Targa(void);
|
||||
~Targa();
|
||||
|
||||
/* Function prototypes. */
|
||||
long Open(const char* name, long mode);
|
||||
void Close(void);
|
||||
|
||||
long Load(const char* name, char* palette, char* image,bool invert_image=true);
|
||||
long Load(const char* name, long flags, bool invert_image=true);
|
||||
long Save(const char* name, long flags, bool addextension = false);
|
||||
|
||||
void XFlip(void);
|
||||
void YFlip(void);
|
||||
|
||||
char* SetImage(char* buffer);
|
||||
char* GetImage(void) const {return (mImage);}
|
||||
|
||||
char* SetPalette(char* buffer);
|
||||
char* GetPalette(void) const {return (mPalette);}
|
||||
|
||||
bool IsCompressed(void);
|
||||
|
||||
TGA2Extension* GetExtension(void);
|
||||
|
||||
TGAHeader Header;
|
||||
|
||||
protected:
|
||||
#ifdef TGA_USES_WWLIB_FILE_CLASSES
|
||||
FileClass *TGAFile;
|
||||
#else
|
||||
long mFH;
|
||||
#endif
|
||||
long mAccess;
|
||||
long mFlags;
|
||||
char* mImage;
|
||||
char* mPalette;
|
||||
TGA2Extension mExtension;
|
||||
|
||||
private:
|
||||
// Utility functions
|
||||
long DecodeImage(void);
|
||||
long EncodeImage(void);
|
||||
void InvertImage(void);
|
||||
|
||||
// These functions are for ease of ifdef'ing between standard io calls
|
||||
// and FileClass.
|
||||
void Clear_File(void);
|
||||
bool Is_File_Open(void);
|
||||
bool File_Open_Read(const char* name);
|
||||
bool File_Open_Write(const char* name);
|
||||
bool File_Open_ReadWrite(const char* name);
|
||||
int File_Seek(int pos, int dir);
|
||||
int File_Read(void *buffer, int size);
|
||||
int File_Write(void *buffer, int size);
|
||||
};
|
||||
|
||||
#endif /* _TARGA_H_ */
|
||||
|
||||
238
Code/wwlib/WWCOMUtil.cpp
Normal file
238
Code/wwlib/WWCOMUtil.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* $Archive: /Commando/Code/wwlib/WWCOMUtil.cpp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* COM utility functions and macros
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Denzil E. Long, Jr.
|
||||
* $Author: Denzil_l $
|
||||
*
|
||||
* VERSION INFO
|
||||
* $Revision: 2 $
|
||||
* $Modtime: 8/02/01 3:00p $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "WWCOMUtil.h"
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* Dispatch_GetProperty
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* INPUTS
|
||||
* Dispatch - Dispatch interface pointer.
|
||||
* Property - Name of property to get.
|
||||
* Value - Property value.
|
||||
*
|
||||
* RESULT
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
STDMETHODIMP Dispatch_GetProperty(IDispatch* object, const OLECHAR* propName,
|
||||
VARIANT* result)
|
||||
{
|
||||
result->vt = VT_EMPTY;
|
||||
result->lVal = 0;
|
||||
|
||||
// Get the dispid for the named property
|
||||
OLECHAR* member = const_cast<OLECHAR*>(propName);
|
||||
DISPID dispid;
|
||||
HRESULT hr = object->GetIDsOfNames(IID_NULL, &member, 1,
|
||||
LOCALE_SYSTEM_DEFAULT, &dispid);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// Get the property
|
||||
DISPPARAMS params = {NULL, NULL, 0, 0};
|
||||
UINT argErr = 0;
|
||||
hr = object->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
|
||||
DISPATCH_PROPERTYGET, ¶ms, result, NULL, &argErr);
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* Dispatch_PutProperty
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* INPUTS
|
||||
* Dispatch - Dispatch interface pointer.
|
||||
* Property - Name of property to put.
|
||||
* Value - Property value.
|
||||
*
|
||||
* RESULT
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
STDMETHODIMP Dispatch_PutProperty(IDispatch* object, const OLECHAR* propName,
|
||||
VARIANT* propValue)
|
||||
{
|
||||
// Get the dispid for the named property
|
||||
OLECHAR* member = const_cast<OLECHAR*>(propName);
|
||||
DISPID dispid;
|
||||
|
||||
HRESULT hr = object->GetIDsOfNames(IID_NULL, &member, 1,
|
||||
LOCALE_SYSTEM_DEFAULT, &dispid);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// Get the property
|
||||
DISPPARAMS params = {NULL, NULL, 0, 0};
|
||||
params.cArgs = 1;
|
||||
params.rgvarg = propValue;
|
||||
|
||||
VARIANT result;
|
||||
UINT argErr = 0;
|
||||
|
||||
hr = object->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
|
||||
DISPATCH_PROPERTYPUT, ¶ms, &result, NULL, &argErr);
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* Dispatch_InvokeMethod
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* INPUTS
|
||||
* Dispatch - Dispatch interface pointer.
|
||||
* Method - Method name
|
||||
* Params - Parameters
|
||||
* Result - On return; result of method call
|
||||
*
|
||||
* RESULT
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
STDMETHODIMP Dispatch_InvokeMethod(IDispatch* object, const OLECHAR* methodName,
|
||||
DISPPARAMS* params, VARIANT* result)
|
||||
{
|
||||
// Get the dispid for the named property
|
||||
OLECHAR* member = const_cast<OLECHAR*>(methodName);
|
||||
DISPID dispid;
|
||||
|
||||
HRESULT hr = object->GetIDsOfNames(IID_NULL, &member, 1,
|
||||
LOCALE_SYSTEM_DEFAULT, &dispid);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
UINT argErr = 0;
|
||||
hr = object->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
|
||||
DISPATCH_METHOD, params, result, NULL, &argErr);
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* RegisterCOMServer
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Register an in-process COM server DLL.
|
||||
*
|
||||
* INPUTS
|
||||
* DLLName - Name of DLL to register.
|
||||
*
|
||||
* RESULT
|
||||
* Success - True if operation successful.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
bool RegisterCOMServer(const char* dllName)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
HINSTANCE hInst = LoadLibrary(dllName);
|
||||
|
||||
if (hInst != NULL)
|
||||
{
|
||||
FARPROC regServerProc = GetProcAddress(hInst, "DllRegisterServer");
|
||||
|
||||
if (regServerProc != NULL)
|
||||
{
|
||||
HRESULT hr = regServerProc();
|
||||
success = SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
FreeLibrary(hInst);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* UnregisterCOMServer
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Unregister a in-process COM server DLL.
|
||||
*
|
||||
* INPUTS
|
||||
* DLLName - Name of DLL to unregister.
|
||||
*
|
||||
* RESULT
|
||||
* Success - True if operation successful.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
bool UnregisterCOMServer(const char* dllName)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
HINSTANCE hInst = LoadLibrary(dllName);
|
||||
|
||||
if (hInst != NULL)
|
||||
{
|
||||
FARPROC unregServerProc = GetProcAddress(hInst, "DllUnregisterServer");
|
||||
|
||||
if (unregServerProc != NULL)
|
||||
{
|
||||
HRESULT hr = unregServerProc();
|
||||
success = SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
FreeLibrary(hInst);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
60
Code/wwlib/WWCOMUtil.h
Normal file
60
Code/wwlib/WWCOMUtil.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* NAME
|
||||
* $Archive: /Commando/Code/wwlib/WWCOMUtil.h $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* COM utility functions and macros
|
||||
*
|
||||
* PROGRAMMER
|
||||
* Denzil E. Long, Jr.
|
||||
* $Author: Denzil_l $
|
||||
*
|
||||
* VERSION INFO
|
||||
* $Revision: 3 $
|
||||
* $Modtime: 8/02/01 3:00p $
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __WWCOMUTIL_H__
|
||||
#define __WWCOMUTIL_H__
|
||||
|
||||
#include <oaidl.h>
|
||||
|
||||
//! Invoke PropertyGet on IDispatch interface.
|
||||
HRESULT STDMETHODCALLTYPE Dispatch_GetProperty(IDispatch* object,
|
||||
const OLECHAR* propName, VARIANT* result);
|
||||
|
||||
//! Invoke PropertyPut on IDispatch interface.
|
||||
HRESULT STDMETHODCALLTYPE Dispatch_PutProperty(IDispatch* object,
|
||||
const OLECHAR* propName, VARIANT* propValue);
|
||||
|
||||
//! Invoke Method on IDispatch interface.
|
||||
HRESULT STDMETHODCALLTYPE Dispatch_InvokeMethod(IDispatch* object,
|
||||
const OLECHAR* methodName, DISPPARAMS* params, VARIANT* result);
|
||||
|
||||
//! Register COM in-process DLL server
|
||||
bool RegisterCOMServer(const char* dllName);
|
||||
|
||||
//! Unregister COM in-process DLL server
|
||||
bool UnregisterCOMServer(const char* dllName);
|
||||
|
||||
#endif // __WWCOMUTIL_H__
|
||||
46
Code/wwlib/_convert.cpp
Normal file
46
Code/wwlib/_convert.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/***********************************************************************************************
|
||||
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
|
||||
***********************************************************************************************
|
||||
* *
|
||||
* Project Name : Command & Conquer *
|
||||
* *
|
||||
* $Archive:: /Commando/Code/Library/_Convert.cpp $*
|
||||
* *
|
||||
* $Author:: Byon_g $*
|
||||
* *
|
||||
* $Modtime:: 2/10/98 4:20p $*
|
||||
* *
|
||||
* $Revision:: 2 $*
|
||||
* *
|
||||
*---------------------------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#include "always.h"
|
||||
#include "_convert.h"
|
||||
|
||||
ConvertClass * VoxelDrawer = NULL;
|
||||
ConvertClass * UnitDrawer = NULL;
|
||||
ConvertClass * TerrainDrawer = NULL;
|
||||
ConvertClass * AnimDrawer = NULL;
|
||||
ConvertClass * NormalDrawer = NULL;
|
||||
ConvertClass * IsometricDrawer = NULL;
|
||||
|
||||
49
Code/wwlib/_convert.h
Normal file
49
Code/wwlib/_convert.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/***********************************************************************************************
|
||||
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
|
||||
***********************************************************************************************
|
||||
* *
|
||||
* Project Name : Command & Conquer *
|
||||
* *
|
||||
* $Archive:: /Commando/Library/_Convert.h $*
|
||||
* *
|
||||
* $Author:: Greg_h $*
|
||||
* *
|
||||
* $Modtime:: 7/22/97 11:37a $*
|
||||
* *
|
||||
* $Revision:: 1 $*
|
||||
* *
|
||||
*---------------------------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef _CONVERT_H
|
||||
#define _CONVERT_H
|
||||
|
||||
#include "convert.h"
|
||||
|
||||
extern ConvertClass * VoxelDrawer;
|
||||
extern ConvertClass * UnitDrawer;
|
||||
extern ConvertClass * TerrainDrawer;
|
||||
extern ConvertClass * AnimDrawer;
|
||||
extern ConvertClass * NormalDrawer;
|
||||
extern ConvertClass * IsometricDrawer;
|
||||
|
||||
#endif
|
||||
47
Code/wwlib/_mono.cpp
Normal file
47
Code/wwlib/_mono.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/***********************************************************************************************
|
||||
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
|
||||
***********************************************************************************************
|
||||
* *
|
||||
* Project Name : Command & Conquer *
|
||||
* *
|
||||
* $Archive:: /Commando/Library/_mono.cpp $*
|
||||
* *
|
||||
* $Author:: Greg_h $*
|
||||
* *
|
||||
* $Modtime:: 7/22/97 11:37a $*
|
||||
* *
|
||||
* $Revision:: 1 $*
|
||||
* *
|
||||
*---------------------------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#include "always.h"
|
||||
#include "_mono.h"
|
||||
|
||||
|
||||
/*
|
||||
** This is the global (general purpose) mono object. It exists only for the convenience of
|
||||
** debugging mono printing.
|
||||
*/
|
||||
MonoClass Mono;
|
||||
|
||||
|
||||
52
Code/wwlib/_mono.h
Normal file
52
Code/wwlib/_mono.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** 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/>.
|
||||
*/
|
||||
|
||||
/***********************************************************************************************
|
||||
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
|
||||
***********************************************************************************************
|
||||
* *
|
||||
* Project Name : Command & Conquer *
|
||||
* *
|
||||
* $Archive:: /G/wwlib/_mono.h $*
|
||||
* *
|
||||
* $Author:: Eric_c $*
|
||||
* *
|
||||
* $Modtime:: 4/02/99 11:58a $*
|
||||
* *
|
||||
* $Revision:: 2 $*
|
||||
* *
|
||||
*---------------------------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
#ifndef _MONO_H
|
||||
#define _MONO_H
|
||||
|
||||
#include "mono.h"
|
||||
|
||||
|
||||
/*
|
||||
** This externs the global mono object. There can be only one.
|
||||
*/
|
||||
extern MonoClass Mono;
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user